Day 13 (minified version)
This commit is contained in:
11
day13/part2-minified.py
Normal file
11
day13/part2-minified.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from functools import reduce
|
||||
from math import gcd
|
||||
lcm = lambda a, b: abs(a*b) // gcd(a, b)
|
||||
def merge(a, b, x, y):
|
||||
while b != y:
|
||||
if b < y:
|
||||
b += a * ((y-b-1) // a + 1)
|
||||
else:
|
||||
y += x * ((b-y-1) // x + 1)
|
||||
return lcm(a, x), b
|
||||
print(reduce(lambda fn, fm: merge(*fn, *fm), ((int(x), -idx) for idx, x in enumerate([x.strip() for x in open("input.txt")][1].split(',')) if x != 'x'), (1, 0))[1])
|
||||
Reference in New Issue
Block a user