-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday25.py
More file actions
56 lines (41 loc) · 1.4 KB
/
day25.py
File metadata and controls
56 lines (41 loc) · 1.4 KB
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
from aocd.models import Puzzle
def solve_puzzle_one(input):
cpk = input[0]
dpk = input[1]
print(cpk)
print(dpk)
pks = calc_pks()
cpk_ls = pks[cpk]
dpk_ls = pks[dpk]
assert transform(cpk_ls, dpk) == transform(dpk_ls, cpk)
print(transform(dpk_ls, cpk))
def transform(lz, sn):
v = 1
for _ in range(lz):
v = v * sn
v = v % 20201227
return v
def calc_pks(sn=7):
d = {}
v = 1
for i in range(1, 20000000):
v = v * sn
v = v % 20201227
d[v] = i
return d
def parse_input(data):
return int(data.splitlines()[0]), int(data.splitlines()[1])
test_input = """5764801
17807724"""
# parse single line: data.splitlines() || np.array(data.splitlines())
# parse integer: np.fromstring(puzzle.input_data, dtype=int, sep='\n')
# parse with regex: [parse("{low:d}-{high:d} {char:l}: {pass:w}", line) for line in data.split("\n")]
# parse string as chars: np.array(lmap(list, data.split("\n")), dtype=object)
# parse and store to dict: [dict([pp.split(":") for pp in re.split(r"\s", line)]) for line in data.split("\n\n")]
# parse and store to set: [lmap(set, group.split("\n")) for group in data.split("\n\n")]
if __name__ == '__main__':
puzzle = Puzzle(year=2020, day=25)
input = puzzle.input_data
if False:
input = test_input
solve_puzzle_one(parse_input(input.strip()))