mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
remove internal/util
This commit is contained in:
parent
0f48ed35ea
commit
aeb57b5cca
@ -6,8 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Solve(buf []byte) (int, error) {
|
func Solve(buf []byte) (int, error) {
|
||||||
@ -31,8 +29,8 @@ func parseLines(r io.Reader) ([]int, []int, error) {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
nums := strings.Fields(scanner.Text())
|
nums := strings.Fields(scanner.Text())
|
||||||
|
|
||||||
left = util.InsertSorted(left, util.MustConv(nums[0]))
|
left = insertSorted(left, mustConv(nums[0]))
|
||||||
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
right = insertSorted(right, mustConv(nums[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package util
|
package one
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MustConv(s string) int {
|
func mustConv(s string) int {
|
||||||
n, err := strconv.Atoi(s)
|
n, err := strconv.Atoi(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -14,7 +14,7 @@ func MustConv(s string) int {
|
|||||||
return n
|
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)
|
i, _ := slices.BinarySearch(ts, t)
|
||||||
return slices.Insert(ts, i, t)
|
return slices.Insert(ts, i, t)
|
||||||
}
|
}
|
@ -6,8 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-01/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Solve(buf []byte) (int, error) {
|
func Solve(buf []byte) (int, error) {
|
||||||
@ -43,8 +41,8 @@ func parseLines(r io.Reader) (map[int]int, []int, error) {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
nums := strings.Fields(scanner.Text())
|
nums := strings.Fields(scanner.Text())
|
||||||
|
|
||||||
left[util.MustConv(nums[0])]++
|
left[mustConv(nums[0])]++
|
||||||
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
right = insertSorted(right, mustConv(nums[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
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