From 2d02f553aa4cc4ded630628eccdf34f55937cee5 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 14 Dec 2016 20:19:02 +0100 Subject: Add 2015 sources --- 2015/day17.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2015/day17.hs (limited to '2015/day17.hs') 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 -- cgit v1.2.3-70-g09d2