mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-14 13:59:51 +01:00
Add 2015 day 17
This commit is contained in:
20
haskellAoC/inputs/2015/17
Normal file
20
haskellAoC/inputs/2015/17
Normal 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
|
||||
23
haskellAoC/src/Y2015/Day17.hs
Normal file
23
haskellAoC/src/Y2015/Day17.hs
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user