Day 4: 470

This commit is contained in:
Christoph Stahl 2021-12-04 17:26:34 +01:00
parent 89fda9b41c
commit 22f2d0cfcb

View file

@ -6,17 +6,16 @@ l=Left
i=isRight
c=isLeft
e=[]:e
s[]=[]
s(v:t)|'.'>v=' ':s t|let=v:s t
s(v:t)|'.'>v=[]:s t|(x:u)<-s t=(v:x):u
v[]=[]
v s=tail(take 6 s):v(drop 6 s)
d%i|i==l d=r d|let=i
a=m.m.m.(%)
k d i|i==l d=r d|let=i
a=m.m.m.k
h=any$all i
x!d|h d||h(foldr(z(:))e d)=r$(x*)$sum$lefts=<<d|let=l 0
(x:y)#f=m(x!)(a x f):y#a x f
a?b|c a,i b=b|let=l 0
q i=(\(a:b:_)->z(?)a b)$drop(length(takeWhile(any c)i)-1)i
q i=(\(b,h:_)->z(?)(last b)h)$span(any c)i
w p(n,t)=head$rights$p(n#t)
p(x:y)=(m read$words$s x,v$m(m(l.read).words)y)
p(x:y)=(m read$s x,v$m(m(l.read).words)y)
main=interact$show.((,).w q<*>w(filter i=<<)).p.lines