summaryrefslogtreecommitdiff
path: root/2020/5.hs
diff options
context:
space:
mode:
Diffstat (limited to '2020/5.hs')
-rw-r--r--2020/5.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/2020/5.hs b/2020/5.hs
new file mode 100644
index 0000000..51c9bca
--- /dev/null
+++ b/2020/5.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE LambdaCase #-}
+module Main (main) where
+
+import Data.List (sort)
+import Numeric (readInt)
+
+import Input
+
+
+parse :: String -> Int
+parse = fst . head . readInt 2 (`elem` "FBLR") (\case 'F' -> 0 ; 'B' -> 1 ; 'L' -> 0 ; 'R' -> 1 ; _ -> undefined)
+
+main :: IO ()
+main = do
+ input <- map parse <$> getInput 5
+ print (maximum input)
+ print (fst (head (filter ((== 2) . snd) (zipWith (\a b -> (a+1, b-a)) (sort input) (tail (sort input))))))