Day 2: 222

This commit is contained in:
Christoph Stahl 2021-12-04 02:46:55 +01:00
parent 41711114e9
commit 5a2408185d

View file

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