Copyright | (c) Eric Mertens 2020 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2020/day/14
>>> :{ let cmds = parseInput "mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0Xn mem[8] = 11n mem[7] = 101n mem[8] = 0n" in run1 [] IntMap.empty cmds :} 165 >>> :{ let cmds = parseInput "mask = 000000000000000000000000000000X1001Xn mem[42] = 100n mask = 00000000000000000000000000000000X0XXn mem[26] = 1n" in run2 [] IntMap.empty cmds :} 208
Synopsis
- type Cmd = Either [M] (Int, Int)
- data M
- parseInput :: String -> Input
- getInput :: Int -> Int -> IO Input
- type Input = [Either [M] (Int, Int)]
- main :: IO ()
- run1 :: [M] -> IntMap Int -> [Cmd] -> Int
- mask1 :: Int -> Int -> [M] -> Int
- run2 :: [M] -> IntMap Int -> [Cmd] -> Int
- mask2 :: Int -> Int -> [M] -> [Int]
Documentation
parseInput :: String -> Input Source #
Simulate the computer using the mask1
rule.
Apply a mask where 1
and 0
overwrite bits.
>>>
mask1 11 6 [M1,MX,MX,MX,MX,M0,MX]
73
>>>
mask1 101 6 [M1,MX,MX,MX,MX,M0,MX]
101
>>>
mask1 0 6 [M1,MX,MX,MX,MX,M0,MX]
64
Simulate the computer using the mask2
rule.