day24
This commit is contained in:
parent
4328f27544
commit
32486160f0
44
day24/day.go
Normal file
44
day24/day.go
Normal file
@ -0,0 +1,44 @@
|
||||
package day24
|
||||
|
||||
import (
|
||||
"math"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func findMinQE(packageWeights []int, weightPerCompartment int) int {
|
||||
var results [][]int
|
||||
for i := 1; i < len(packageWeights); i++ {
|
||||
for _, comb := range tools.CombinationsInt(packageWeights, i) {
|
||||
if tools.Sum(comb...) == weightPerCompartment {
|
||||
results = append(results, comb)
|
||||
}
|
||||
}
|
||||
if len(results) > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
minQE := math.MaxInt64
|
||||
for _, result := range results {
|
||||
thisQE := tools.Mul(result...)
|
||||
if thisQE < minQE {
|
||||
minQE = thisQE
|
||||
}
|
||||
}
|
||||
|
||||
return minQE
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
packageWeights := puzzle.GetInputArrayInt()
|
||||
weightPerCompartment := tools.Sum(packageWeights...) / 3
|
||||
|
||||
return findMinQE(packageWeights, weightPerCompartment)
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
packageWeights := puzzle.GetInputArrayInt()
|
||||
weightPerCompartment := tools.Sum(packageWeights...) / 4
|
||||
|
||||
return findMinQE(packageWeights, weightPerCompartment)
|
||||
}
|
||||
2
main.go
2
main.go
@ -24,6 +24,7 @@ import (
|
||||
"aoc2015/day21"
|
||||
"aoc2015/day22"
|
||||
"aoc2015/day23"
|
||||
"aoc2015/day24"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -64,6 +65,7 @@ func initDayFunctions() {
|
||||
21: {1: day21.Part1, 2: day21.Part2},
|
||||
22: {1: day22.Part1, 2: day22.Part2},
|
||||
23: {1: day23.Part1, 2: day23.Part2},
|
||||
24: {1: day24.Part1, 2: day24.Part2},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user