diff --git a/day-01/internal/one/solve.go b/day-01/internal/one/solve.go index 24d6f09..4d34f43 100644 --- a/day-01/internal/one/solve.go +++ b/day-01/internal/one/solve.go @@ -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])) diff --git a/day-01/internal/two/solve.go b/day-01/internal/two/solve.go index b0683b2..5f2c07d 100644 --- a/day-01/internal/two/solve.go +++ b/day-01/internal/two/solve.go @@ -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]))