From 0a249b85fc66e57cabb30ee2c789b1c19134c2f2 Mon Sep 17 00:00:00 2001 From: Parnic Date: Sun, 12 Jun 2022 23:48:14 -0500 Subject: [PATCH] Use varargs for GetPermutations --- days/07.go | 4 ++-- utilities/permutations.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/days/07.go b/days/07.go index 42d3503..5ba4c9d 100644 --- a/days/07.go +++ b/days/07.go @@ -28,7 +28,7 @@ func (d *Day07) Part1() string { var highestVal 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 { if len(sequence) != len(d.amps) { panic("input sequence does not match up to number of amplifiers") @@ -68,7 +68,7 @@ func (d *Day07) Part2() string { var highestVal 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 { if len(sequence) != len(d.amps) { panic("input sequence does not match up to number of amplifiers") diff --git a/utilities/permutations.go b/utilities/permutations.go index fa220b3..e2b0b8b 100644 --- a/utilities/permutations.go +++ b/utilities/permutations.go @@ -4,7 +4,7 @@ type Permutable interface { ~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) res := [][]T{}