-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathDay5.java
46 lines (36 loc) · 838 Bytes
/
Day5.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.sbaars.adventofcode.year17.days;
import com.sbaars.adventofcode.year17.Day2017;
public class Day5 extends Day2017 {
public Day5() {
super(5);
}
public static void main(String[] args) {
new Day5().printParts();
}
@Override
public Object part1() {
int[] jumps = dayIntStream().toArray();
int pos = 0;
int steps = 0;
while (pos >= 0 && pos < jumps.length) {
int jump = jumps[pos];
jumps[pos]++;
pos += jump;
steps++;
}
return steps;
}
@Override
public Object part2() {
int[] jumps = dayIntStream().toArray();
int pos = 0;
int steps = 0;
while (pos >= 0 && pos < jumps.length) {
int jump = jumps[pos];
jumps[pos] += (jump >= 3) ? -1 : 1;
pos += jump;
steps++;
}
return steps;
}
}