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:
+3
-4
@@ -5,8 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/mathy"
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
)
|
||||
|
||||
@@ -52,11 +51,11 @@ func taxicab(input string, part int) int {
|
||||
row += dirs[dirIndex][0]
|
||||
col += dirs[dirIndex][1]
|
||||
if visited[[2]int{row, col}] && part == 2 {
|
||||
return mathutil.ManhattanDistance(0, 0, row, col)
|
||||
return mathy.ManhattanDistance(0, 0, row, col)
|
||||
}
|
||||
visited[[2]int{row, col}] = true
|
||||
}
|
||||
}
|
||||
|
||||
return mathutil.ManhattanDistance(0, 0, row, col)
|
||||
return mathy.ManhattanDistance(0, 0, row, col)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
@@ -20,6 +21,9 @@ func Test_part1(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if strings.Contains(tt.name, "part2") && testing.Short() {
|
||||
t.Skip("Skipping long test, 2016/day14, a lot of MD5 hashes")
|
||||
}
|
||||
if got := oneTimePad(tt.input, tt.part); got != tt.want {
|
||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||
"github.com/alexchao26/advent-of-code-go/mathy"
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ func firewall(input string, part int) int {
|
||||
for _, r := range allBlockedRanges {
|
||||
endOfLastRange := merged[len(merged)-1][1]
|
||||
if endOfLastRange >= r[0]-1 {
|
||||
merged[len(merged)-1][1] = mathutil.MaxInt(endOfLastRange, r[1])
|
||||
merged[len(merged)-1][1] = mathy.MaxInt(endOfLastRange, r[1])
|
||||
} else {
|
||||
merged = append(merged, r)
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||
"github.com/alexchao26/advent-of-code-go/mathy"
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
)
|
||||
|
||||
@@ -54,8 +54,8 @@ func part2(input string) int {
|
||||
var maxX, maxY int
|
||||
var x, y int
|
||||
for c, n := range nodes {
|
||||
maxX = mathutil.MaxInt(c[0], maxX)
|
||||
maxY = mathutil.MaxInt(c[1], maxY)
|
||||
maxX = mathy.MaxInt(c[0], maxX)
|
||||
maxY = mathy.MaxInt(c[1], maxY)
|
||||
// getting the starting node, i.e. has zero used space
|
||||
if n.used == 0 {
|
||||
x = n.coord[1]
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/cast"
|
||||
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||
"github.com/alexchao26/advent-of-code-go/mathy"
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
)
|
||||
|
||||
@@ -127,7 +127,7 @@ func dfs(graph [][]int, entryIndex int, visited map[int]bool, returnToZero bool)
|
||||
visited[i] = true
|
||||
|
||||
dist := val + dfs(graph, i, visited, returnToZero)
|
||||
minDistance = mathutil.MinInt(minDistance, dist)
|
||||
minDistance = mathy.MinInt(minDistance, dist)
|
||||
|
||||
delete(visited, i)
|
||||
}
|
||||
|
||||
@@ -20,20 +20,3 @@ func Test_part1(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_part2(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want int
|
||||
}{
|
||||
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := part2(tt.input); got != tt.want {
|
||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user