From 7ef83667ac748b75687326483ac89de788597c02 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Tue, 29 Dec 2020 08:45:18 +0100 Subject: [PATCH] incomplete day17 --- day17/day.go | 40 ++++++++++++++++++++++++++++++++++++++++ inputs/17 | 20 ++++++++++++++++++++ inputs/17_test | 5 +++++ main.go | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 day17/day.go create mode 100644 inputs/17 create mode 100644 inputs/17_test diff --git a/day17/day.go b/day17/day.go new file mode 100644 index 0000000..ed0c308 --- /dev/null +++ b/day17/day.go @@ -0,0 +1,40 @@ +package day17 + +import ( + "fmt" + "sort" + "tools" +) + +func getCombinations(containers []int, sum int) (combinations [][]int) { + for i, c := range containers { + if c > sum { + break + } else if c == sum { + return [][]int{{c}} + } else if i == len(containers)-1 { + break + } + subCombinations := getCombinations(containers[i:], sum-c) + for _, v := range subCombinations { + subCombination := append([]int{c}, v...) + combinations = append(combinations, subCombination) + } + } + return combinations +} + +func Part1(puzzle tools.AoCPuzzle) interface{} { + input := puzzle.GetInputArrayInt() + sort.Ints(input) + + combos25 := getCombinations(input, 25) + fmt.Println(combos25) + //combos150 := getCombinations(input, 150) + + return len(combos25) +} + +func Part2(puzzle tools.AoCPuzzle) interface{} { + return 0 +} diff --git a/inputs/17 b/inputs/17 new file mode 100644 index 0000000..16af5f3 --- /dev/null +++ b/inputs/17 @@ -0,0 +1,20 @@ +33 +14 +18 +20 +45 +35 +16 +35 +1 +13 +18 +13 +50 +44 +48 +6 +24 +41 +30 +42 \ No newline at end of file diff --git a/inputs/17_test b/inputs/17_test new file mode 100644 index 0000000..3b9a375 --- /dev/null +++ b/inputs/17_test @@ -0,0 +1,5 @@ +20 +15 +10 +5 +5 \ No newline at end of file diff --git a/main.go b/main.go index e03c131..61fe5aa 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( "aoc2015/day14" "aoc2015/day15" "aoc2015/day16" + "aoc2015/day17" "flag" "fmt" "os" @@ -50,6 +51,7 @@ func initDayFunctions() { 14: {1: day14.Part1, 2: day14.Part2}, 15: {1: day15.Part1, 2: day15.Part2}, 16: {1: day16.Part1, 2: day16.Part2}, + 17: {1: day17.Part1, 2: day17.Part2}, } }