File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
src/main/java/com/sbaars/adventofcode/year17/days Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,28 @@ public Object part1() {
63
63
64
64
@ Override
65
65
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 ;
67
89
}
68
90
}
You can’t perform that action at this time.
0 commit comments