summaryrefslogtreecommitdiff
path: root/2015/day17.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-12-14 20:19:02 +0100
committertomsmeding <tom.smeding@gmail.com>2016-12-14 20:19:02 +0100
commit2d02f553aa4cc4ded630628eccdf34f55937cee5 (patch)
treed5377ebdff68788725b5820d5331ce7b6c9d4a84 /2015/day17.hs
parent97b4c5d86cc12447ac6845e25a863e26a88aec35 (diff)
Add 2015 sources
Diffstat (limited to '2015/day17.hs')
-rw-r--r--2015/day17.hs20
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