Add 2015 day 17

This commit is contained in:
Xavier Morel
2020-12-19 17:38:35 +01:00
parent cb202e0284
commit 0a8366cc7b
3 changed files with 45 additions and 0 deletions

20
haskellAoC/inputs/2015/17 Normal file
View File

@@ -0,0 +1,20 @@
11
30
47
31
32
36
3
1
5
3
32
36
15
11
46
26
28
1
19
3

View File

@@ -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

View File

@@ -16,6 +16,7 @@ import Y2015.Day13
import Y2015.Day14 import Y2015.Day14
import Y2015.Day15 import Y2015.Day15
import Y2015.Day16 import Y2015.Day16
import Y2015.Day17
year2015 :: String -> [String] -> (String, String) year2015 :: String -> [String] -> (String, String)
year2015 "01" = y15day01 year2015 "01" = y15day01
@@ -34,3 +35,4 @@ year2015 "13" = y15day13
year2015 "14" = y15day14 year2015 "14" = y15day14
year2015 "15" = y15day15 year2015 "15" = y15day15
year2015 "16" = y15day16 year2015 "16" = y15day16
year2015 "17" = y15day17