From 887894c0fcac84e6acac50fdfe45624a8934361d Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Wed, 8 Dec 2021 13:53:31 +0100 Subject: [PATCH] Day 8: 520 --- d8golf.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 d8golf.hs diff --git a/d8golf.hs b/d8golf.hs new file mode 100644 index 0000000..5732199 --- /dev/null +++ b/d8golf.hs @@ -0,0 +1,22 @@ +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