blob: 48ca1f78bc602a5bcddf3e58dda457f312e50782 (
plain)
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
|
#!/usr/bin/python
def coord_list(until):
return result
def solve_part1(until):
# Generate a list of table (row, col) coordinates in the order
# that are filled by the algorithm described in the puzzle text.
coords = []
r = 1
c = 0
while (r, c) != until:
if r == 1:
r = c + 1
c = 1
else:
r -= 1
c += 1
coords.append((r, c))
code = 20151125 # first code is given
for i in range(1, len(coords)):
code *= 252533
code %= 33554393
return code
def main():
# Read target coordinate from input text file
with open("input.txt", "r") as f:
words = f.read().split()
row = int(words[-3].rstrip(","))
col = int(words[-1].rstrip("."))
coord = (row, col)
print("Part 1 solution:", solve_part1(coord)) # 19980801 for me
if __name__ == "__main__":
main()
|