17 lines
683 B
Haskell
17 lines
683 B
Haskell
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 _=[]
|
|
|
|
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
|