-
Notifications
You must be signed in to change notification settings - Fork 0
/
day25.py
42 lines (34 loc) · 763 Bytes
/
day25.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
import sys
from itertools import count
from utils import iterate, nth
def main():
row, col = parse(sys.stdin.readline())
print('part 1: ', code(row - 1, col - 1))
def code(row, col):
return nth(iterate(next_code, 20151125), ns(row, col))
def next_code(code):
return code*252533 % 33554393
"""
| 0 1 2 3 4 5
---+---+---+---+---+---+---+
0 | 0 2 5 9 14 20
1 | 1 4 8 13 19
2 | 3 7 12 18
3 | 6 11 17
4 | 10 16
5 | 15
"""
def ns(row, col):
i = 0
for m in count(0):
for x in range(m + 1):
if x == col and m - x == row:
return i
i += 1
def parse(line):
import re
return map(int, re.findall(r'\d+', line))
if __name__ == '__main__':
import doctest
doctest.testmod()
main()