8000 Day 25 · l0s/advent-of-code-java@e20ca94 · GitHub
[go: up one dir, main page]

Skip to content

Commit e20ca94

Browse files
committed
Day 25
1 parent ddc8d3e commit e20ca94

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/test/java/com/macasaet/Day25.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.macasaet;
2+
3+
import java.io.IOException;
4+
import java.util.stream.Collectors;
5+
import java.util.stream.StreamSupport;
6+
7+
public class Day25 {
8+
9+
public static void main(final String[] args) throws IOException {
10+
try (var spliterator = new LineSpliterator(Day22.class.getResourceAsStream("/day-25-input.txt"))) {
11+
final var publicKeys = StreamSupport.stream(spliterator, false)
12+
.map(Integer::parseInt)
13+
.collect(Collectors.toUnmodifiableList());
14+
final int cardPublicKey = publicKeys.get(0);
15+
final int doorPublicKey = publicKeys.get(1);
16+
final long initialSubjectNumber = 7;
17+
18+
int cardLoopSize = 0;
19+
for (long value = 1; value != cardPublicKey; cardLoopSize++) {
20+
value = transformOnce(value, initialSubjectNumber);
21+
}
22+
System.out.println("cardLoopSize: " + cardLoopSize);
23+
24+
int doorLoopSize = 0;
25+
for (long value = 1; value != doorPublicKey; doorLoopSize++) {
26+
value = transformOnce(value, initialSubjectNumber);
27+
}
28+
System.out.println("doorLoopSize: " + doorLoopSize);
29+
30+
final long e1 = transformCompletely(doorPublicKey, cardLoopSize);
31+
final long e2 = transformCompletely(cardPublicKey, doorLoopSize);
32+
System.out.println("e1: " + e1);
33+
System.out.println("e2: " + e2);
34+
}
35+
}
36+
37+
protected static long transformCompletely(final long subjectNumber, final int loopSize) {
38+
long value = 1;
39+
for (int i = loopSize; --i >= 0; value = transformOnce(value, subjectNumber)) ;
40+
return value;
41+
}
42+
43+
protected static long transformOnce(final long value, final long subjectNumber) {
44+
return (value * subjectNumber) % 20201227;
45+
}
46+
47+
}

0 commit comments

Comments
 (0)
0