Use varargs for GetPermutations
This commit is contained in:
@ -28,7 +28,7 @@ func (d *Day07) Part1() string {
|
|||||||
var highestVal int64
|
var highestVal int64
|
||||||
var highestSequence []int64
|
var highestSequence []int64
|
||||||
|
|
||||||
allSequences := utilities.GetPermutations([]int64{0, 1, 2, 3, 4})
|
allSequences := utilities.GetPermutations([]int64{0, 1, 2, 3, 4}...)
|
||||||
for _, sequence := range allSequences {
|
for _, sequence := range allSequences {
|
||||||
if len(sequence) != len(d.amps) {
|
if len(sequence) != len(d.amps) {
|
||||||
panic("input sequence does not match up to number of amplifiers")
|
panic("input sequence does not match up to number of amplifiers")
|
||||||
@ -68,7 +68,7 @@ func (d *Day07) Part2() string {
|
|||||||
var highestVal int64
|
var highestVal int64
|
||||||
var highestSequence []int64
|
var highestSequence []int64
|
||||||
|
|
||||||
allSequences := utilities.GetPermutations([]int64{5, 6, 7, 8, 9})
|
allSequences := utilities.GetPermutations([]int64{5, 6, 7, 8, 9}...)
|
||||||
for _, sequence := range allSequences {
|
for _, sequence := range allSequences {
|
||||||
if len(sequence) != len(d.amps) {
|
if len(sequence) != len(d.amps) {
|
||||||
panic("input sequence does not match up to number of amplifiers")
|
panic("input sequence does not match up to number of amplifiers")
|
||||||
|
@ -4,7 +4,7 @@ type Permutable interface {
|
|||||||
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
|
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPermutations[T Permutable](arr []T) [][]T {
|
func GetPermutations[T Permutable](arr ...T) [][]T {
|
||||||
var helper func([]T, int)
|
var helper func([]T, int)
|
||||||
res := [][]T{}
|
res := [][]T{}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user