day17 solved
This commit is contained in:
parent
7ef83667ac
commit
a0415caa4a
32
day17/day.go
32
day17/day.go
@ -1,7 +1,6 @@
|
|||||||
package day17
|
package day17
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sort"
|
"sort"
|
||||||
"tools"
|
"tools"
|
||||||
)
|
)
|
||||||
@ -11,11 +10,14 @@ func getCombinations(containers []int, sum int) (combinations [][]int) {
|
|||||||
if c > sum {
|
if c > sum {
|
||||||
break
|
break
|
||||||
} else if c == sum {
|
} else if c == sum {
|
||||||
return [][]int{{c}}
|
combinations = append(combinations, []int{c})
|
||||||
|
if i == len(containers)-1 || containers[i+1] != sum {
|
||||||
|
return combinations
|
||||||
|
}
|
||||||
} else if i == len(containers)-1 {
|
} else if i == len(containers)-1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
subCombinations := getCombinations(containers[i:], sum-c)
|
subCombinations := getCombinations(containers[i+1:], sum-c)
|
||||||
for _, v := range subCombinations {
|
for _, v := range subCombinations {
|
||||||
subCombination := append([]int{c}, v...)
|
subCombination := append([]int{c}, v...)
|
||||||
combinations = append(combinations, subCombination)
|
combinations = append(combinations, subCombination)
|
||||||
@ -28,13 +30,27 @@ func Part1(puzzle tools.AoCPuzzle) interface{} {
|
|||||||
input := puzzle.GetInputArrayInt()
|
input := puzzle.GetInputArrayInt()
|
||||||
sort.Ints(input)
|
sort.Ints(input)
|
||||||
|
|
||||||
combos25 := getCombinations(input, 25)
|
combos150 := getCombinations(input, 150)
|
||||||
fmt.Println(combos25)
|
|
||||||
//combos150 := getCombinations(input, 150)
|
|
||||||
|
|
||||||
return len(combos25)
|
return len(combos150)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||||
return 0
|
input := puzzle.GetInputArrayInt()
|
||||||
|
sort.Ints(input)
|
||||||
|
|
||||||
|
// REVISIT! This does not account for the fact, that a container might be re-used
|
||||||
|
// Still, the answer is correct for the given input.
|
||||||
|
|
||||||
|
combos150 := getCombinations(input, 150)
|
||||||
|
minNumContainers := len(input)
|
||||||
|
numContainers := make(map[int]int)
|
||||||
|
for _, v := range combos150 {
|
||||||
|
numContainers[len(v)]++
|
||||||
|
if len(v) < minNumContainers {
|
||||||
|
minNumContainers = len(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return numContainers[minNumContainers]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user