diff options
Diffstat (limited to 'execs/Day14.hs')
-rw-r--r-- | execs/Day14.hs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/execs/Day14.hs b/execs/Day14.hs index 7f4368a..e1e0e37 100644 --- a/execs/Day14.hs +++ b/execs/Day14.hs | |||
@@ -1,15 +1,15 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Utils | 3 | import Data.Bifunctor (bimap) |
4 | import Text.ParserCombinators.Parsec | ||
5 | import Text.Parsec.Char | ||
6 | import Data.Either | ||
7 | import Data.Char | 4 | import Data.Char |
8 | import Data.Bifunctor (bimap) | 5 | import Data.Either |
6 | import Data.Map (Map) | ||
7 | import qualified Data.Map as Map | ||
9 | import Data.Strings | 8 | import Data.Strings |
10 | import Numeric (showIntAtBase, readInt) | 9 | import Numeric (readInt, showIntAtBase) |
11 | import Data.Map (Map) | 10 | import Text.Parsec.Char |
12 | import qualified Data.Map as Map | 11 | import Text.ParserCombinators.Parsec |
12 | import Utils | ||
13 | 13 | ||
14 | data Stmt = Mask String | Mem Int Int deriving Show | 14 | data Stmt = Mask String | Mem Int Int deriving Show |
15 | 15 | ||
@@ -41,9 +41,9 @@ runProgram ls = sum regs | |||
41 | where nval = applyMask val m | 41 | where nval = applyMask val m |
42 | 42 | ||
43 | floatings :: String -> [String] | 43 | floatings :: String -> [String] |
44 | floatings [] = [[]] | 44 | floatings [] = [[]] |
45 | floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b]) | 45 | floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b]) |
46 | floatings (x:xs) = map (x:) $ floatings xs | 46 | floatings (x:xs) = map (x:) $ floatings xs |
47 | 47 | ||
48 | genIdxs :: Int -> String -> [Int] | 48 | genIdxs :: Int -> String -> [Int] |
49 | genIdxs v m = map (fst . head . readInt 2 (`elem` "01") digitToInt) (floatings wm) | 49 | genIdxs v m = map (fst . head . readInt 2 (`elem` "01") digitToInt) (floatings wm) |