aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-05 06:00:02 +0000
committerAkshay <[email protected]>2020-12-05 06:00:02 +0000
commite0a5d9cbf99c2d6bbaef12f2ce5506eda0ba5bec (patch)
tree808605db33eeb4a78178a1b207ecc1e03ccd8a2d /execs
parent4c0b08c857afb6f308e01c19e5df68b994617311 (diff)
ohno im retarded
Diffstat (limited to 'execs')
-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