Day 13 (cleanup)
This commit is contained in:
@@ -14,12 +14,11 @@ def merge(a, b, x, y):
|
|||||||
b += a * ((y-b-1) // a + 1)
|
b += a * ((y-b-1) // a + 1)
|
||||||
else:
|
else:
|
||||||
y += x * ((b-y-1) // x + 1)
|
y += x * ((b-y-1) // x + 1)
|
||||||
d = b
|
return lcm(a, x), b
|
||||||
c = lcm(a, x)
|
|
||||||
return c, d
|
|
||||||
|
|
||||||
|
|
||||||
lines = [x.strip() for x in open("input.txt")]
|
lines = [x.strip() for x in open("input.txt")]
|
||||||
|
# f(n) = [interval] * n + [offset] --> (interval, offset)
|
||||||
busses = ((int(x), -idx) for idx, x in enumerate(lines[1].split(',')) if x != 'x')
|
busses = ((int(x), -idx) for idx, x in enumerate(lines[1].split(',')) if x != 'x')
|
||||||
sequence = reduce(lambda fn, fm: merge(*fn, *fm), busses, (1, 0))
|
sequence = reduce(lambda fn, fm: merge(*fn, *fm), busses, (1, 0))
|
||||||
print(sequence[1])
|
print(sequence[1])
|
||||||
|
|||||||
Reference in New Issue
Block a user