Day 8: 359
This commit is contained in:
parent
887894c0fc
commit
507a186db4
1 changed files with 3 additions and 21 deletions
24
d8golf.hs
24
d8golf.hs
|
@ -1,22 +1,4 @@
|
||||||
import Data.List
|
import Data.List
|
||||||
q"012345"=pure 0
|
r(p,o)=map(\h->last(h:[p|h==o]))
|
||||||
q"12"=pure 1
|
main=interact$show.((,).sum.map(foldl1$(+).(10*))<*>length.filter(`elem`[1,4,7,8]).concat).map(drop 10.t.filter(/="|").words).lines
|
||||||
q"01346"=pure 2
|
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]]
|
||||||
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
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue