feat: complete day 1

main
sgoudham 2 years ago
parent 513641d092
commit ea30be2bf3
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -1,2 +0,0 @@
SESSION=YOUR_SESSION_COOKIE
YEAR=2022

@ -1,16 +1,28 @@
{-# LANGUAGE OverloadedStrings #-}
module Days.Day01 (day01) where
import AOC (Solution (..))
import qualified Data.Text as T
import Data.List (sort)
import Data.Text qualified as T
import Data.Text.Read qualified as T
day01 :: Solution
day01 = Solution parseInput part1 part2
parseInput :: T.Text -> a
parseInput = error "parseInput not defined for day 01"
parseInput :: T.Text -> [[Int]]
-- parseInput caloriesString = T.splitOn "\n\n" caloriesString
parseInput caloriesString = intList
where
split = T.splitOn "\n\n" caloriesString
strList = map T.lines split
intList = map (\x -> map unwrap (map T.decimal x)) strList
unwrap intList' = case intList' of
Left a -> error a
Right (b, _) -> b
part1 :: a -> Int
part1 = error "part1 not defined for day 01"
part1 :: [[Int]] -> Int
part1 list = maximum $ map (\x -> sum x) list
part2 :: a -> Int
part2 = error "part2 not defined for day 01"
part2 :: [[Int]] -> Int
part2 list = sum $ take 3 $ reverse $ sort $ map (\x -> sum x) list

Loading…
Cancel
Save