7 from Data.Map import :: Map(..)
8 import qualified Data.Map as DM
10 read :: *File -> [Char]
12 # (ok, c, f) = freadc f
18 # ls = split ['\n'] $ read io
19 = (sum $ 'DM'.elems $ one [] ls 'DM'.newMap)
21 toBin :: (Int -> [Char])
22 toBin = tob [35,34..0]
25 | n >= 2^b = ['1':tob bs (n-2^b)]
28 fromBin :: ([Char] -> Int)
29 fromBin = foldr (\a b->a+2*b) 0 o map digitToInt
31 one :: [Char] [[Char]] -> ((Map Int Int) -> Map Int Int)
32 one _ [['mask = ':mask]:xs] = one mask xs
33 one mask [['mem[':rest]:xs]
34 = case span isDigit rest of
36 = one mask xs o 'DM'.put (toInt $ toString num)
37 (fromBin $ zipWith msk mask $ toBin $ toInt $ toString rest)
39 msk :: Char Char -> Char
43 one mask [[]:xs] = one mask xs