aboutsummaryrefslogtreecommitdiff
path: root/execs/Day05.hs
diff options
context:
space:
mode:
Diffstat (limited to 'execs/Day05.hs')
-rw-r--r--execs/Day05.hs21
1 files changed, 6 insertions, 15 deletions
diff --git a/execs/Day05.hs b/execs/Day05.hs
index c018203..aae8f49 100644
--- a/execs/Day05.hs
+++ b/execs/Day05.hs
@@ -1,21 +1,12 @@
1module Main where 1module Main where
2 2
3data Direction = Upper | Lower 3import Data.Char (digitToInt)
4 4
5doHalf :: [Direction] -> (Int, Int) -> Int 5doValidate = toInt . map readBin
6doHalf ls start = fst $ foldl fn start ls 6toInt = foldl (\a x -> a * 2 + digitToInt x) 0
7 where fn (l, u) Lower = (l, (u+l) `div` 2) 7readBin 'F' = '0'
8 fn (l, u) Upper = ((u+l) `div` 2 + 1, u) 8readBin 'L' = '0'
9 9readBin _ = '1'
10doValidate :: String -> Int
11doValidate s = row * 8 + col
12 where row = flip doHalf (0, 127) $ map readDir (take 7 s)
13 col = flip doHalf (0, 7) $ map readDir (drop 7 s)
14
15readDir :: Char -> Direction
16readDir c
17 | c `elem` "FL" = Lower
18 | otherwise = Upper
19 10
20main :: IO () 11main :: IO ()
21main = do 12main = do