Day 13 (minified version 6)
This commit is contained in:
@@ -1 +1 @@
|
||||
from functools import reduce; from math import gcd; lcm = lambda a, b: abs(a*b) // gcd(a, b); merge = lambda a, b, x, y: (lcm(a, x), b) if b == y else merge(a, b + a * (max(-1, y-b-1) // a + 1), x, y + x * (max(-1, b-y-1) // x + 1)); 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])
|
||||
import functools;import math;lcm=lambda a,b:abs(a*b)//math.gcd(a,b);merge=lambda a,b,x,y:(lcm(a,x),b)if b==y else merge(a,b+a*(max(-1,y-b-1)//a+1),x,y+x*(max(-1,b-y-1)//x+1));print(functools.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