diff --git a/src/Years/Y2015/Day2.idr b/src/Years/Y2015/Day2.idr index fec965d..77409c6 100644 --- a/src/Years/Y2015/Day2.idr +++ b/src/Years/Y2015/Day2.idr @@ -22,6 +22,16 @@ record Box where (.slack) (MkBox length width height) = foldl1 min [length * width, width * height, length * height] +(.ribbon) : Box -> Integer +(.ribbon) (MkBox length width height) = + foldl1 min [2 * (length + width), 2 * (length + height), 2 * (width + height)] + +(.bow) : Box -> Integer +(.bow) (MkBox length width height) = length * width * height + +totalRibbon : Box -> Integer +totalRibbon x = x.ribbon + x.bow + paperNeeded : Box -> Integer paperNeeded x = x.area + x.slack @@ -35,13 +45,16 @@ parseBox str = do height <- note "Failed parsing height: \{show h}" $ parsePositive h pure $ MkBox length width height -part1 : Eff (PartEff String) (Integer, ()) +part1 : Eff (PartEff String) (Integer, List Box) part1 = do input <- map lines $ askAt "input" boxes <- traverse parseBox input let output = sum . map paperNeeded $ boxes - pure (output, ()) + pure (output, boxes) + +part2 : (boxes : List Box) -> Eff (PartEff String) Integer +part2 boxes = pure . sum . map totalRibbon $ boxes public export day2 : Day -day2 = First 2 part1 +day2 = Both 2 part1 part2