get rid of named match groups

This commit is contained in:
2024-12-03 15:43:58 +00:00
parent d32b376619
commit fca32422e4
3 changed files with 11 additions and 25 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/onyx-and-iris/aoc2024/day-03/internal/util"
)
var reMul = regexp.MustCompile(`mul\((?P<first>[0-9]{1,3}),(?P<second>[0-9]{1,3})\)`)
var reMul = regexp.MustCompile(`mul\(([0-9]{1,3}),([0-9]{1,3})\)`)
func Solve(data []byte) (int, error) {
r := bytes.NewReader(data)
@@ -26,10 +26,9 @@ func parseLines(r io.Reader) (int, error) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
m := reMul.FindAllString(scanner.Text(), -1)
for _, v := range m {
groups := util.GetGroups(reMul, v)
sum += util.MustConv(groups["first"]) * util.MustConv(groups["second"])
matches := reMul.FindAllStringSubmatch(scanner.Text(), -1)
for _, m := range matches {
sum += util.MustConv(m[1]) * util.MustConv(m[2])
}
}