Day 11: 647
This commit is contained in:
parent
94612e6674
commit
55570239c3
1 changed files with 7 additions and 7 deletions
14
day11.hs
14
day11.hs
|
@ -1,15 +1,15 @@
|
||||||
import Control.Monad.State.Strict
|
import Control.Monad.State
|
||||||
import Data.List
|
import Data.List
|
||||||
data M=M{n::[Int],w::Int,k::Int->Int,z::[Int]}
|
|
||||||
l=map
|
l=map
|
||||||
v=length
|
v=length
|
||||||
(!)=drop
|
(!)=drop
|
||||||
|
n(a,w,k,z)=a
|
||||||
m"*"=(*);m"+"=(+)
|
m"*"=(*);m"+"=(+)
|
||||||
"old"%x=x;i%_=read i
|
"old"%x=x;i%_=read i
|
||||||
q[a,t,b]x=m t(a%x)(b%x)
|
q[a,t,b]x=m t(a%x)(b%x)
|
||||||
i#o=modify((\(f,(c:b))->f++(o c:b)).splitAt i)
|
i#o=modify((\(f,(c:b))->f++(o c:b)).splitAt i)
|
||||||
c n o=product.take 2.reverse.sort.l w.(execState=<<s n o.v)
|
c n o=product.take 2.reverse.sort.l(\(_,a,_,_)->a).(execState=<<s n o.v)
|
||||||
b o m i|u<-o$k m i,[d,t,f]<-z m=last(f:[t|mod u d==0])# \c->c{n=u:n c}
|
b o(n,w,k,[d,t,f])i|u<-o$k i=last(f:[t|mod u d==0])# \(n,w,k,z)->(u:n,w,k,z)
|
||||||
p[_,i,o,d,t,f]=M(read$'[':18!i++"]")0(q$words$19!o)(l(read.last.words)[d,t,f])
|
p[_,i,o,d,t,f]=(read$'[':18!i++"]",0,q$words$19!o,l(read.last.words)[d,t,f])
|
||||||
s i o m=forM([0..i]>>[0..m-1])$ \i->(!!i)<$>get>>=(forM.n<*>b o)>>i# \c->c{n=[],w=w c+v(n c)}
|
s i o m=forM([0..i]>>[0..m-1])$ \i->(!!i)<$>get>>=(forM.n<*>b o)>>i# \(n,w,k,z)->([],w+v n,k,z)
|
||||||
main=interact$show.(\m->[c 9999(`mod`((product.l(head.z))m))m,c 19(`div`3)m]).l(p.filter(/="")).groupBy(const(/="")).lines
|
main=interact$show.(\m->[c 9999(`mod`(product.l(head. \(a,w,k,z)->z))m)m,c 19(`div`3)m]).l(p.filter(/="")).groupBy(\x->(/="")).lines
|
||||||
|
|
Loading…
Add table
Reference in a new issue