mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 06:10:47 +00:00
remove internal/util
This commit is contained in:
parent
0f48ed35ea
commit
aeb57b5cca
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
@ -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 {
|
||||
|
20
day-01/internal/two/util.go
Normal file
20
day-01/internal/two/util.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user