diff --git a/day-01/internal/one/solve.go b/day-01/internal/one/solve.go index 0bf254a..fe4a930 100644 --- a/day-01/internal/one/solve.go +++ b/day-01/internal/one/solve.go @@ -6,8 +6,6 @@ import ( "io" "math" "strings" - - "github.com/onyx-and-iris/aoc2024/day-01/internal/util" ) func Solve(buf []byte) (int, error) { @@ -31,8 +29,8 @@ func parseLines(r io.Reader) ([]int, []int, error) { for scanner.Scan() { nums := strings.Fields(scanner.Text()) - left = util.InsertSorted(left, util.MustConv(nums[0])) - right = util.InsertSorted(right, util.MustConv(nums[1])) + left = insertSorted(left, mustConv(nums[0])) + right = insertSorted(right, mustConv(nums[1])) } if err := scanner.Err(); err != nil { diff --git a/day-01/internal/util/util.go b/day-01/internal/one/util.go similarity index 65% rename from day-01/internal/util/util.go rename to day-01/internal/one/util.go index 88876bf..18b32d0 100644 --- a/day-01/internal/util/util.go +++ b/day-01/internal/one/util.go @@ -1,4 +1,4 @@ -package util +package one import ( "cmp" @@ -6,7 +6,7 @@ import ( "strconv" ) -func MustConv(s string) int { +func mustConv(s string) int { n, err := strconv.Atoi(s) if err != nil { panic(err) @@ -14,7 +14,7 @@ func MustConv(s string) int { return n } -func InsertSorted[T cmp.Ordered](ts []T, t T) []T { +func insertSorted[T cmp.Ordered](ts []T, t T) []T { i, _ := slices.BinarySearch(ts, t) return slices.Insert(ts, i, t) } diff --git a/day-01/internal/two/solve.go b/day-01/internal/two/solve.go index 13b9353..c12ca9f 100644 --- a/day-01/internal/two/solve.go +++ b/day-01/internal/two/solve.go @@ -6,8 +6,6 @@ import ( "io" "slices" "strings" - - "github.com/onyx-and-iris/aoc2024/day-01/internal/util" ) func Solve(buf []byte) (int, error) { @@ -43,8 +41,8 @@ func parseLines(r io.Reader) (map[int]int, []int, error) { for scanner.Scan() { nums := strings.Fields(scanner.Text()) - left[util.MustConv(nums[0])]++ - right = util.InsertSorted(right, util.MustConv(nums[1])) + left[mustConv(nums[0])]++ + right = insertSorted(right, mustConv(nums[1])) } if err := scanner.Err(); err != nil { diff --git a/day-01/internal/two/util.go b/day-01/internal/two/util.go new file mode 100644 index 0000000..92ea5c2 --- /dev/null +++ b/day-01/internal/two/util.go @@ -0,0 +1,20 @@ +package two + +import ( + "cmp" + "slices" + "strconv" +) + +func mustConv(s string) int { + n, err := strconv.Atoi(s) + if err != nil { + panic(err) + } + return n +} + +func insertSorted[T cmp.Ordered](ts []T, t T) []T { + i, _ := slices.BinarySearch(ts, t) + return slices.Insert(ts, i, t) +}