blob: 12e921746b7e96f87ff50d56ab12254b011d09b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
|