Day 8: 520
This commit is contained in:
parent
582997dbb6
commit
887894c0fc
1 changed files with 22 additions and 0 deletions
22
d8golf.hs
Normal file
22
d8golf.hs
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue