diff --git a/haskellAoC/inputs/2015/17 b/haskellAoC/inputs/2015/17 new file mode 100644 index 0000000..35ae125 --- /dev/null +++ b/haskellAoC/inputs/2015/17 @@ -0,0 +1,20 @@ +11 +30 +47 +31 +32 +36 +3 +1 +5 +3 +32 +36 +15 +11 +46 +26 +28 +1 +19 +3 \ No newline at end of file diff --git a/haskellAoC/src/Y2015/Day17.hs b/haskellAoC/src/Y2015/Day17.hs new file mode 100644 index 0000000..cef27a9 --- /dev/null +++ b/haskellAoC/src/Y2015/Day17.hs @@ -0,0 +1,23 @@ +module Y2015.Day17 (y15day17) where + +import Data.List + +getCombinations :: Int -> [Int] -> [[Int]] +getCombinations _ [] = [] +getCombinations tgt (nb:[]) + | nb == tgt = [[nb]] + | otherwise = [] +getCombinations tgt (nb:t) + | nb > tgt = [] + | nb == tgt = [[nb]] ++ nextWithoutNb + | otherwise = nextWithNb ++ nextWithoutNb + where nextWithNb = map (\c -> [nb] ++ c) $ getCombinations (tgt - nb) t + nextWithoutNb = getCombinations tgt t + +y15day17 :: [String] -> (String, String) +y15day17 input = (part1, part2) + where part1 = show $ length $ combs + part2 = show $ length $ head $ group $ sort $ map (length) $ combs + + numbers = sort $ map read input :: [Int] + combs = getCombinations 150 numbers diff --git a/haskellAoC/src/Y2015/Days.hs b/haskellAoC/src/Y2015/Days.hs index 6552f7d..36ebe35 100644 --- a/haskellAoC/src/Y2015/Days.hs +++ b/haskellAoC/src/Y2015/Days.hs @@ -16,6 +16,7 @@ import Y2015.Day13 import Y2015.Day14 import Y2015.Day15 import Y2015.Day16 +import Y2015.Day17 year2015 :: String -> [String] -> (String, String) year2015 "01" = y15day01 @@ -34,3 +35,4 @@ year2015 "13" = y15day13 year2015 "14" = y15day14 year2015 "15" = y15day15 year2015 "16" = y15day16 +year2015 "17" = y15day17