From ea30be2bf37bcf29581bfeeca35f75d37782e4d5 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 1 Dec 2022 23:59:22 +0000 Subject: [PATCH] feat: complete day 1 --- .env.example | 2 -- solutions/Days/Day01.hs | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 87e3f5e..0000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -SESSION=YOUR_SESSION_COOKIE -YEAR=2022 \ No newline at end of file diff --git a/solutions/Days/Day01.hs b/solutions/Days/Day01.hs index a2ef1ab..27adeff 100644 --- a/solutions/Days/Day01.hs +++ b/solutions/Days/Day01.hs @@ -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