Browse Source

Add day 13

master
mid-kid 4 years ago
parent
commit
17f4e35631
  1. 20
      d13.py
  2. 2
      d13_input.txt
  3. 2
      d13_output.txt

20
d13.py

@ -0,0 +1,20 @@
#!/usr/bin/env python3
from sys import argv
i = open(argv[1]).read().split("\n")
a = int(i[0].strip())
b = [int(x) if x != "x" else None for x in i[1].strip().split(",")]
e = sorted([(x, x-(a%x)) for x in b if x], key=lambda x: x[1])[0]
print(e[0]*e[1])
ma = [(i, x) for i, x in enumerate(b) if x]
ma.sort(key=lambda x: x[1], reverse=True)
s = ma[0][1]-ma[0][0]
m = ma[0][1]
for i, x in ma[1:]:
while x-(s%x) != (i%x if i%x != 0 else x):
s += m
m *= x
print(s)

2
d13_input.txt

@ -0,0 +1,2 @@
1001796
37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,457,x,x,x,x,x,x,x,x,x,x,x,x,13,17,x,x,x,x,x,x,x,x,23,x,x,x,x,x,29,x,431,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19

2
d13_output.txt

@ -0,0 +1,2 @@
261
807435693182510
Loading…
Cancel
Save