advent-of-code/2015/day02/day02.hs

16 lines
459 B
Haskell
Raw Normal View History

2024-12-02 21:14:08 +11:00
import Aoc
import Data.List.Split
parseFile :: [String] -> [(Int, Int, Int)]
parseFile = map $ triplet . map read . splitOn "x"
part1 :: [(Int, Int, Int)] -> Int
part1 = sum . map wrapping
where wrapping (l, w, h) = let areas = [l*w, l*h, w*h] in 2*sum areas + minimum areas
part2 :: [(Int, Int, Int)] -> Int
part2 = sum . map wrapping
where wrapping (l, w, h) = 2*minimum [l+w, l+h, w+h] + l*w*h
main :: IO ()
main = aocMain parseFile part1 part2