Day 14: 461
This commit is contained in:
parent
05bd0464d9
commit
57a8c392b7
1 changed files with 9 additions and 17 deletions
26
d14golf.hs
26
d14golf.hs
|
@ -1,17 +1,9 @@
|
||||||
import qualified Data.Map as M
|
import Data.List
|
||||||
l=readFile"d14small"
|
s(x:y:z)=([x,y],1):s(y:z);s _=[]
|
||||||
i :: [(String, Char)] -> String -> String
|
m((x,i):z)|(h,t)<-span((==x).fst)z=(x,i+sum(map snd h)):m t;m _ = []
|
||||||
i r[x] = [x]
|
c#(s,i)|Just a<-map((*i)<$>)<$>lookup s c=a
|
||||||
i r(a:b:x)|Just c<-lookup [a,b] r=a:c:i r(b:x)
|
t=((m.sort).).(=<<).(#)
|
||||||
split(x:y:xs)=[x,y]:split(y:xs)
|
c i=foldr(\([a,b],i)x->(a,i):(b,i):x)[(head i,1),(last i,1)]
|
||||||
split _=[]
|
d i (x,r)|a<-map((`div`2).snd)$m$sort$c x(iterate(t r)(s x)!!i)=maximum a-minimum a
|
||||||
|
u(a:b)c=(a:b,[([a,c],1),(c:b,1)])
|
||||||
apply :: M.Map String Int -> M.Map String (M.Map String Int) -> M.Map String Int
|
main=interact$show.((,).d 40<*>d 10).(\(x:_,_:y)->(x,map(u.take 2<*>(!!6))y)).break(==[]).lines
|
||||||
apply innermap conf = M.mapWithKey (undefined) innermap
|
|
||||||
|
|
||||||
step conf init = M.map (id) conf
|
|
||||||
|
|
||||||
makeTuple(a:b)c=(a:b,(M.fromList[([a,c],1),(c:b,1)],M.fromList[(c,1)]))
|
|
||||||
parse :: String -> ([String],M.Map String (M.Map String Int,M.Map Char Int))
|
|
||||||
parse = (\([x],_:y)->(split x,(M.fromList.map((makeTuple).take 2<*>(!!6)))y)).break(==[]).lines
|
|
||||||
--main=interact$show.length.(!!40).(\([x],r)->iterate(i r)x).parse
|
|
Loading…
Add table
Reference in a new issue