14 lines
No EOL
482 B
Haskell
14 lines
No EOL
482 B
Haskell
m=map.map
|
|
(?)=splitAt
|
|
w=filter
|
|
y=maybe
|
|
n=Nothing
|
|
v g m(x,y)|x>=0,y>=0,(f,r:b)<-x?m,(h,c:t)<-y?r=f++(h++g c:t):b|let=m
|
|
s(x,y)=(,)<$>[x-1..x+1]<*>[y-1..y+1]
|
|
m#(x,y)=m!!x!!y
|
|
a=[0..9]
|
|
p!m=w(p.(m#))$(,)<$>a<*>a
|
|
(%)i j z=((i+1,j+length((==n)!z)),m(y 0 id)z)
|
|
t((n,j),i)=n%j$l$m(pure.(+1))i
|
|
l i|a@(h:t)<-y(2<1)(>9)!i=l$foldl(v((+1)<$>))(foldl(v(pure n))i a)$s=<<a|let=i
|
|
main=interact$show.((,).(fst.fst.(head.w(all(==0).concat.snd)))<*>snd.fst.(!!100)).iterate t.(,)(0,0).m(read.pure).lines |