never executed always true always false
1 {-|
2 Module: Y2015.D17
3 Description: Advent of Code Day 17 Solutions.
4 License: MIT
5 Maintainer: @tylerjl
6
7 Solutions to the day 17 set of problems for <adventofcode.com>.
8 -}
9
10 module Y2015.D17 (filledAmong, minFilledAmong) where
11
12 import Data.Function (on)
13 import Data.List (subsequences, minimumBy)
14
15 -- |Finds how many combinations of containers can fit a volume of nog
16 filledAmong :: Int -- ^ Length
17 -> String -- ^ List of container sizes
18 -> Int -- ^ Number of combinations
19 filledAmong t = containersBy length t . c
20 where c = map read . lines
21
22 -- |Finds how many combinations of containers the ideal combination can
23 -- |fit a volume of nog
24 minFilledAmong :: Int -- ^ Length
25 -> String -- ^ List of container sizes
26 -> Int -- ^ Number of combinations
27 minFilledAmong t s = containersBy (length . filter ((==) minFilled . length)) t c
28 where c = map read $ lines s
29 minFilled = containersBy (length . minimumBy (compare `on` length)) t c
30
31 containersBy :: ([[Int]] -> a) -> Int -> [Int] -> a
32 containersBy f t s = f [x | x <- subsequences s, sum x == t]