Skip to content

Commit eb1fd20

Browse files
authored
Create Day5.java
1 parent 0faabf9 commit eb1fd20

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Day5.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* --- Day 5: A Maze of Twisty Trampolines, All Alike ---
3+
*/
4+
public class Day5 {
5+
6+
public static int part1(int[] maze) {
7+
int steps = 0;
8+
int i = 0;
9+
while (i < maze.length) {
10+
i = i + maze[i]++;
11+
steps++;
12+
}
13+
14+
return steps;
15+
}
16+
17+
public static int part2(int[] maze) {
18+
int steps = 0;
19+
int i = 0;
20+
while (i < maze.length) {
21+
int next = i + maze[i];
22+
maze[i] += (maze[i] >= 3 ? -1 : 1);
23+
i = next;
24+
steps++;
25+
}
26+
27+
return steps;
28+
}
29+
}

0 commit comments

Comments
 (0)