mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2026-04-09 02:23:36 +00:00
get rid of named match groups
This commit is contained in:
@@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user