mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
28 lines
497 B
Go
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
|
||
|
}
|