Day 2: 232

This commit is contained in:
Christoph Stahl 2021-12-02 21:09:50 +01:00
parent f009aff1eb
commit f75b36b26b

View file

@ -1,3 +1,4 @@
q(h:f:_)(d,n)|"f"<d=[h-n,f]|"f">d=[h+n,f]|let=[h,f+n]
p[h,f,a](d,n)|"f"<d=[h,f,a-n]|"f">d=[h,f,a+n]|let=[h+n,f+n*a,a]
q(h:f:_)(d,n)|"f"==d=[h,f+n]|let=[d%h$n,f]
p[h,f,a](d,n)|"f"==d=[h+n,f+n*a,a]|let=[h,f,d%a$n]
(%)d|"f"<d=(-)|let=(+)
main=interact$show.(<$>[p,q]).((\(a:b:_)->a*b).).flip(`foldl`[0,0,0]).map(fmap read.splitAt 1.map head.words).lines