Day 11: 647

This commit is contained in:
Christoph Stahl 2022-12-11 21:27:35 +01:00
parent 94612e6674
commit 55570239c3

View file

@ -1,15 +1,15 @@
import Control.Monad.State.Strict
import Control.Monad.State
import Data.List
data M=M{n::[Int],w::Int,k::Int->Int,z::[Int]}
l=map
v=length
(!)=drop
n(a,w,k,z)=a
m"*"=(*);m"+"=(+)
"old"%x=x;i%_=read i
q[a,t,b]x=m t(a%x)(b%x)
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)
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}
p[_,i,o,d,t,f]=M(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)}
main=interact$show.(\m->[c 9999(`mod`((product.l(head.z))m))m,c 19(`div`3)m]).l(p.filter(/="")).groupBy(const(/="")).lines
c n o=product.take 2.reverse.sort.l(\(_,a,_,_)->a).(execState=<<s n o.v)
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]=(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# \(n,w,k,z)->([],w+v n,k,z)
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