mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
37 lines
826 B
Go
37 lines
826 B
Go
|
package main
|
||
|
|
||
|
// multiplyBy unfolds all records by a given factor
|
||
|
func multiplyRawBy(factor int, original []int) []int {
|
||
|
multiplied := []int{}
|
||
|
for i := 0; i < factor; i++ {
|
||
|
multiplied = append(multiplied, original...)
|
||
|
if i < factor-1 {
|
||
|
multiplied = append(multiplied, UNKNOWN)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return multiplied
|
||
|
}
|
||
|
|
||
|
// multiplyBy unfolds all records by a given factor
|
||
|
func multiplyFormatBy(factor int, original []int) []int {
|
||
|
multiplied := []int{}
|
||
|
for i := 0; i < factor; i++ {
|
||
|
multiplied = append(multiplied, original...)
|
||
|
}
|
||
|
|
||
|
return multiplied
|
||
|
}
|
||
|
|
||
|
// two returns the sum of all unfolded arrangement counts
|
||
|
func two(lines []string) int {
|
||
|
fnTracker = newTracker()
|
||
|
sum := 0
|
||
|
for _, record := range records {
|
||
|
raw := record.raw()
|
||
|
sum += count(multiplyRawBy(5, raw), multiplyFormatBy(5, record.format))
|
||
|
}
|
||
|
|
||
|
return sum
|
||
|
}
|