Day 14: Part2 in progress
This commit is contained in:
parent
6053c185cd
commit
05bd0464d9
1 changed files with 12 additions and 4 deletions
16
d14golf.hs
16
d14golf.hs
|
@ -1,9 +1,17 @@
|
|||
import Data.List
|
||||
import qualified Data.Map as M
|
||||
l=readFile"d14small"
|
||||
i :: [(String, Char)] -> String -> String
|
||||
i r[x] = [x]
|
||||
i r(a:b:x)|Just c<-lookup [a,b] r=a:c:i r(b:x)
|
||||
split(x:y:xs)=[x,y]:split(y:xs)
|
||||
split _=[]
|
||||
|
||||
parse :: String -> ([String],[(String, Char)])
|
||||
parse = fmap (map((,).take 2<*>(!!6)).tail).break(==[]).lines
|
||||
main=interact$show.length.(!!40).(\([x],r)->iterate(i r)x).parse
|
||||
apply :: M.Map String Int -> M.Map String (M.Map String Int) -> M.Map String Int
|
||||
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