mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
remove regex, use strings.Fields instead
This commit is contained in:
parent
c3fa7d0ff8
commit
600d01660c
@ -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]))
|
||||
|
@ -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]))
|
||||
|
Loading…
Reference in New Issue
Block a user