Day 4: 491

This commit is contained in:
Christoph Stahl 2021-12-04 16:41:43 +01:00
parent a533e5dfd0
commit 89fda9b41c

22
d4golf.hs Normal file
View file

@ -0,0 +1,22 @@
import Data.Either
m=map
z=zipWith
r=pure
l=Left
i=isRight
c=isLeft
e=[]:e
s[]=[]
s(v:t)|'.'>v=' ':s t|let=v:s t
v[]=[]
v s=tail(take 6 s):v(drop 6 s)
d%i|i==l d=r d|let=i
a=m.m.m.(%)
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
w p(n,t)=head$rights$p(n#t)
p(x:y)=(m read$words$s x,v$m(m(l.read).words)y)
main=interact$show.((,).w q<*>w(filter i=<<)).p.lines