remove regex, use strings.Fields instead

This commit is contained in:
onyx-and-iris 2024-12-02 18:28:28 +00:00
parent c3fa7d0ff8
commit 600d01660c
2 changed files with 4 additions and 8 deletions

View File

@ -5,13 +5,11 @@ import (
"bytes"
"io"
"math"
"regexp"
"strings"
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
)
var reNums = regexp.MustCompile(`[0-9]+`)
func Solve(data []byte) (int, error) {
r := bytes.NewReader(data)
left, right, err := parseLines(r)
@ -31,7 +29,7 @@ func parseLines(r io.Reader) ([]int, []int, error) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
nums := reNums.FindAllString(scanner.Text(), -1)
nums := strings.Fields(scanner.Text())
left = util.InsertSorted(left, util.MustConv(nums[0]))
right = util.InsertSorted(right, util.MustConv(nums[1]))

View File

@ -4,14 +4,12 @@ import (
"bufio"
"bytes"
"io"
"regexp"
"slices"
"strings"
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
)
var reNums = regexp.MustCompile(`[0-9]+`)
func Solve(data []byte) (int, error) {
r := bytes.NewReader(data)
left, right, err := parseLines(r)
@ -43,7 +41,7 @@ func parseLines(r io.Reader) (map[int]int, []int, error) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
nums := reNums.FindAllString(scanner.Text(), -1)
nums := strings.Fields(scanner.Text())
left[util.MustConv(nums[0])]++
right = util.InsertSorted(right, util.MustConv(nums[1]))