aoc2023/day-4/two.go
2023-12-04 17:23:02 +00:00

28 lines
497 B
Go

package main
// Cards represents a single card.
// it tracks its matching numbers and occurrences
type Card struct {
matches int
occurrences int
}
var cards = []Card{}
// two returns the total number of occurrences for all cards
func two(lines []string) (int, error) {
var sum = 0
for i := range cards {
cards[i].occurrences++
for j := i + 1; j <= i+cards[i].matches; j++ {
cards[j].occurrences += cards[i].occurrences
}
sum += cards[i].occurrences
}
return sum, nil
}