Day 8: 359

This commit is contained in:
Christoph Stahl 2021-12-08 17:21:43 +01:00
parent 887894c0fc
commit 507a186db4

View file

@ -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]]