mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
36 lines
651 B
Go
36 lines
651 B
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// one computes points based on matching numbers
|
|
func one(lines []string) (int, error) {
|
|
|
|
f := func(c rune) bool {
|
|
return !unicode.IsDigit(c)
|
|
}
|
|
|
|
sum := 0
|
|
cards = make([]Card, len(lines))
|
|
for x, line := range lines {
|
|
winning, mynums := func() (string, string) {
|
|
y := strings.Split(line, ":")
|
|
z := strings.Split(y[1], "|")
|
|
return z[0], z[1]
|
|
}()
|
|
|
|
m, err := compare(strings.FieldsFunc(winning, f), strings.FieldsFunc(mynums, f))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
cards[x].matches = m
|
|
if cards[x].matches > 0 {
|
|
sum += (pow(2, cards[x].matches-1))
|
|
}
|
|
}
|
|
|
|
return sum, nil
|
|
}
|