From e0a5d9cbf99c2d6bbaef12f2ce5506eda0ba5bec Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 5 Dec 2020 11:30:02 +0530 Subject: ohno im retarded --- execs/Day05.hs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'execs') 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 @@ module Main where -data Direction = Upper | Lower +import Data.Char (digitToInt) -doHalf :: [Direction] -> (Int, Int) -> Int -doHalf ls start = fst $ foldl fn start ls - where fn (l, u) Lower = (l, (u+l) `div` 2) - fn (l, u) Upper = ((u+l) `div` 2 + 1, u) - -doValidate :: String -> Int -doValidate s = row * 8 + col - where row = flip doHalf (0, 127) $ map readDir (take 7 s) - col = flip doHalf (0, 7) $ map readDir (drop 7 s) - -readDir :: Char -> Direction -readDir c - | c `elem` "FL" = Lower - | otherwise = Upper +doValidate = toInt . map readBin +toInt = foldl (\a x -> a * 2 + digitToInt x) 0 +readBin 'F' = '0' +readBin 'L' = '0' +readBin _ = '1' main :: IO () main = do -- cgit v1.2.3