diff options
author | Akshay <[email protected]> | 2020-12-05 06:00:02 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-12-05 06:00:02 +0000 |
commit | e0a5d9cbf99c2d6bbaef12f2ce5506eda0ba5bec (patch) | |
tree | 808605db33eeb4a78178a1b207ecc1e03ccd8a2d | |
parent | 4c0b08c857afb6f308e01c19e5df68b994617311 (diff) |
ohno im retarded
-rw-r--r-- | execs/Day05.hs | 21 |
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 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | data Direction = Upper | Lower | 3 | import Data.Char (digitToInt) |
4 | 4 | ||
5 | doHalf :: [Direction] -> (Int, Int) -> Int | 5 | doValidate = toInt . map readBin |
6 | doHalf ls start = fst $ foldl fn start ls | 6 | toInt = foldl (\a x -> a * 2 + digitToInt x) 0 |
7 | where fn (l, u) Lower = (l, (u+l) `div` 2) | 7 | readBin 'F' = '0' |
8 | fn (l, u) Upper = ((u+l) `div` 2 + 1, u) | 8 | readBin 'L' = '0' |
9 | 9 | readBin _ = '1' | |
10 | doValidate :: String -> Int | ||
11 | doValidate 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 | |||
15 | readDir :: Char -> Direction | ||
16 | readDir c | ||
17 | | c `elem` "FL" = Lower | ||
18 | | otherwise = Upper | ||
19 | 10 | ||
20 | main :: IO () | 11 | main :: IO () |
21 | main = do | 12 | main = do |