Year 2015 Day 2 Part 2
This commit is contained in:
parent
5700e6e9ba
commit
0ba73aa1fd
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue