From 507a186db4ab978bc5cd2e8b40f8574de40ba41f Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Wed, 8 Dec 2021 17:21:43 +0100 Subject: [PATCH] Day 8: 359 --- d8golf.hs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/d8golf.hs b/d8golf.hs index 5732199..de135ff 100644 --- a/d8golf.hs +++ b/d8golf.hs @@ -1,22 +1,4 @@ import Data.List -q"012345"=pure 0 -q"12"=pure 1 -q"01346"=pure 2 -q"01236"=pure 3 -q"1256"=pure 4 -q"02356"=pure 5 -q"023456"=pure 6 -q"012"=pure 7 -q"0123456"=pure 8 -q"012356"=pure 9 -q _=Nothing -t r=head[p|p<-permutations['a'..'g'],Nothing`notElem`map(p%)r] -p%a=q.sort$foldr r a$zip['0'..]p -r(n,o)=foldr(\h a->last(h:[ n|h==o]):a)[] -v(p,n)=map((t p)%)n -f[]=0 -f((Just x):y)=x+10*f y -a=length.filter(`elem`(map pure[1,4,7,8])).concat -b=sum.map(f.reverse) -main=interact$show.((,).b<*>a).map d.lines -d=v.fmap tail.splitAt 10.words +r(p,o)=map(\h->last(h:[p|h==o])) +main=interact$show.((,).sum.map(foldl1$(+).(10*))<*>length.filter(`elem`[1,4,7,8]).concat).map(drop 10.t.filter(/="|").words).lines +t z=head[p|q<-permutations['a'..'g'],Just p<-[mapM((`elemIndex`["012345","12","01346","01236","1256","02356","023456","012","0123456","012356"]).sort.($zip['0'..]q).foldr r)z]]