-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathday_25.py
63 lines (46 loc) · 1.47 KB
/
day_25.py
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
#!/bin/env python
""" Advent of Code Day 25 """
class Day25:
""" Class for processing of day 25 """
def __init__(self):
self.card_key = 0
self.door_key = 0
self.card_loops = {}
self.door_loops = {}
def load_input(self, file_name):
""" load the input """
with open(file_name, "r") as in_file:
lines = [line.rstrip('\n') for line in in_file]
self.card_key = int(lines[0])
self.door_key = int(lines[1])
def get_loop_nr(self, public_key):
""" do the loops """
loops = 0
value = 1
while 1:
loops += 1
value = (value * 7) % 20201227
if value == public_key:
return loops
def do_transform(self, key, times):
""" Do the transformation """
value = 1
for _ in range(1, times + 1):
value = (value * key) % 20201227
return value
def get_task1(self):
""" Get the encryption key """
card_loop_nr = self.get_loop_nr(self.card_key)
key = self.do_transform(self.door_key, card_loop_nr)
print(f"Task1: {key}")
return key
def test_app():
""" Run the tests """
runner = Day25()
runner.load_input("input25_test")
task1_solution = runner.get_task1()
assert task1_solution == 14897079
if __name__ == "__main__":
day_processor = Day25()
day_processor.load_input("input25")
task1 = day_processor.get_task1()