Skip to content

Commit c4ff2d1

Browse files
committed
Implemented 2017 Day 23 Part 2
1 parent 4dc226e commit c4ff2d1

File tree

1 file changed

+23
-1
lines changed
  • src/main/java/com/sbaars/adventofcode/year17/days

1 file changed

+23
-1
lines changed

src/main/java/com/sbaars/adventofcode/year17/days/Day23.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ public Object part1() {
6363

6464
@Override
6565
public Object part2() {
66-
return 0;
66+
// When a = 1, the program essentially counts non-prime numbers in a range
67+
// b starts at 67 * 100 + 100000 = 106700
68+
// c is b + 17000 = 123700
69+
// The program increments h for each non-prime number between b and c, stepping by 17
70+
int b = 106700;
71+
int c = 123700;
72+
int h = 0;
73+
74+
for (int n = b; n <= c; n += 17) {
75+
// Check if n is not prime
76+
boolean isPrime = true;
77+
for (int d = 2; d <= Math.sqrt(n); d++) {
78+
if (n % d == 0) {
79+
isPrime = false;
80+
break;
81+
}
82+
}
83+
if (!isPrime) {
84+
h++;
85+
}
86+
}
87+
88+
return h;
6789
}
6890
}

0 commit comments

Comments
 (0)