diff options
Diffstat (limited to '2015/day17.hs')
-rw-r--r-- | 2015/day17.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/2015/day17.hs b/2015/day17.hs new file mode 100644 index 0000000..9b5af87 --- /dev/null +++ b/2015/day17.hs @@ -0,0 +1,20 @@ +import Control.Monad + +search :: Int -> [Int] -> [[Int]] +search 0 [] = [[]] +search _ [] = [] +search target (sz:szs) + | target < 0 = [] + | target == 0 = [[]] + | target < sz = search target szs + | otherwise = map (sz:) (search (target-sz) szs) ++ search target szs + +day17 :: IO () +day17 = do + input <- liftM (map read . lines) $ readFile "day17.txt" + let fullsearch = search 150 input + minlength = minimum $ map length fullsearch + minposs = filter (\x -> length x == minlength) fullsearch + print $ length minposs -- part 1: do fullsearch instead of minposs + +main = day17 |