mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 12:45:10 +02:00
!changed mathutil package to mathy, removed int/string casting from mathy
This commit is contained in:
+6
-5
@@ -6,7 +6,8 @@ import (
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||
"github.com/alexchao26/advent-of-code-go/cast"
|
||||
"github.com/alexchao26/advent-of-code-go/mathy"
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
)
|
||||
|
||||
@@ -39,7 +40,7 @@ func part1(input string) int {
|
||||
var coordsToBest [2]int
|
||||
distCounts := map[int]int{} // dedeupe equidistant cells
|
||||
for _, coord := range coords {
|
||||
man := mathutil.ManhattanDistance(r, c, coord[0], coord[1])
|
||||
man := mathy.ManhattanDistance(r, c, coord[0], coord[1])
|
||||
if man <= bestManhattan {
|
||||
bestManhattan = man
|
||||
coordsToBest = coord
|
||||
@@ -82,7 +83,7 @@ func part2(input string, dist int) int {
|
||||
for c := boundLeft; c <= boundRight; c++ {
|
||||
point := [2]int{r, c}
|
||||
for _, coord := range coords {
|
||||
coordsToTotalDist[point] += mathutil.ManhattanDistance(point[0], point[1], coord[0], coord[1])
|
||||
coordsToTotalDist[point] += mathy.ManhattanDistance(point[0], point[1], coord[0], coord[1])
|
||||
}
|
||||
if coordsToTotalDist[point] < dist {
|
||||
area++
|
||||
@@ -100,8 +101,8 @@ func parseInputCoords(input string) [][2]int {
|
||||
c := strings.Split(l, ", ")
|
||||
if len(c) == 2 {
|
||||
coords = append(coords, [2]int{
|
||||
mathutil.StrToInt(c[0]),
|
||||
mathutil.StrToInt(c[1]),
|
||||
cast.ToInt(c[0]),
|
||||
cast.ToInt(c[1]),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user