37 lines
919 B
Python
Executable File
37 lines
919 B
Python
Executable File
#!/usr/bin/env python3
|
|
from functools import reduce
|
|
import re, sys
|
|
import math
|
|
import numpy as np
|
|
|
|
def tpl(l):
|
|
me, rest = l.split() # e.g.
|
|
return me, rest
|
|
|
|
fn = sys.argv[1] if len(sys.argv) > 1 else 'input%s' % 13
|
|
with open(fn) as f:
|
|
|
|
lines = [l.strip() for l in f.readlines()]
|
|
start = int(lines[0])
|
|
mehs = [int(x) for x in lines[1].split(',') if x != 'x']
|
|
print(mehs)
|
|
mods = [x - (start % x) for x in mehs]
|
|
dups = sorted(zip(mods, mehs))
|
|
print(np.prod(dups[0]))
|
|
|
|
sched = enumerate(x for x in lines[1].split(','))
|
|
sched = [(a, int(b)) for (a, b) in sched if b != 'x']
|
|
print(sched)
|
|
i = 0
|
|
j = 0
|
|
inc = 1
|
|
while True:
|
|
if (i + sched[j][0]) % sched[j][1] == 0:
|
|
inc *= sched[j][1] # prime
|
|
j += 1
|
|
print(j, f'{i:_}')
|
|
if j == len(sched): # done!
|
|
print(i)
|
|
break
|
|
i += inc
|