diff options
author | Crazazy | 2024-12-01 11:20:14 +0100 |
---|---|---|
committer | Erik Oosting | 2024-12-01 12:01:06 +0100 |
commit | 9f4a26f9188f74aa6869583ab991b4b8eccbb0b7 (patch) | |
tree | f5ab9f0bb6840bc9f91ca5a0bc4bb937481e02b9 /src |
initial commit
why does this take so long ;_;
Diffstat (limited to 'src')
-rw-r--r-- | src/Day1.idr | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Day1.idr b/src/Day1.idr new file mode 100644 index 0000000..12e9217 --- /dev/null +++ b/src/Day1.idr @@ -0,0 +1,30 @@ +module Day1 + +import System +import System.File +import Data.String +import Text.Parser + +parsePair : String -> Maybe (Int, Int) +parsePair pair = do + num1 <- parseInteger (fst p1) + num2 <- parseInteger (snd p2) + pure (num1, num2) where + p1 = span (/= ' ') pair + p2 = span (== ' ') (snd p1) + +parseStr : String -> List (Int, Int) +parseStr str = do + nums <- lines str + maybe [] pure (parsePair nums) + +transposePairs : List (a, b) -> (List a, List b) +transposePairs [] = ([], []) +transposePairs (x :: xs) = ((fst x) :: (fst rest), (snd x) :: (snd rest)) where + rest = transposePairs xs + +main : IO () +main = do + estr <- readFile "data/day1.txt" + str <- either (die . show) pure estr + putStrLn $ show $ transposePairs $ parseStr str |