remove internal/util

This commit is contained in:
onyx-and-iris 2025-01-07 17:18:38 +00:00
parent 0f48ed35ea
commit aeb57b5cca
4 changed files with 27 additions and 11 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}