-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC2020_25.java
73 lines (59 loc) 路 1.77 KB
/
AoC2020_25.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.List;
import com.github.pareronia.aoc.solution.Sample;
import com.github.pareronia.aoc.solution.Samples;
import com.github.pareronia.aoc.solution.SolutionBase;
public class AoC2020_25
extends SolutionBase<AoC2020_25.PublicKeys, Long, String> {
private static final int MOD = 20201227;
private AoC2020_25(final boolean debug) {
super(debug);
}
public static AoC2020_25 create() {
return new AoC2020_25(false);
}
public static AoC2020_25 createDebug() {
return new AoC2020_25(true);
}
private long findLoopSize(final long key) {
long loopSize = 0;
long val = 1;
while (val != key) {
loopSize++;
val = val * 7 % MOD;
}
return loopSize;
}
private long findEncryptionKey(final long pubKey, final long loopSize) {
long val = 1;
for (int i = 0; i < loopSize; i++) {
val = val * pubKey % MOD;
}
return val;
}
@Override
protected PublicKeys parseInput(final List<String> inputs) {
return new PublicKeys(
Long.parseLong(inputs.get(0)),
Long.parseLong(inputs.get(1)));
}
@Override
public Long solvePart1(final PublicKeys keys) {
final long loopSize2 = findLoopSize(keys.key2);
return findEncryptionKey(keys.key1, loopSize2);
}
@Override
public String solvePart2(final PublicKeys keys) {
return "馃巹";
}
@Samples({
@Sample(method = "part1", input = TEST, expected = "14897079")
})
public static void main(final String[] args) throws Exception {
AoC2020_25.create().run();
}
private static final String TEST = """
5764801
17807724
""";
record PublicKeys(long key1, long key2) {}
}