!changed mathutil package to mathy, removed int/string casting from mathy

This commit is contained in:
alexchao26
2020-12-27 17:21:33 -05:00
parent 57fff6d829
commit 666518f507
114 changed files with 780 additions and 287 deletions
+6 -5
View File
@@ -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]),
})
}
}