chore(day17): implent A* path finder
All checks were successful
Go Bump / bump (push) Successful in 8s
Go Test / build (pull_request) Successful in 51s
Go Test / build (push) Successful in 35s

This commit was merged in pull request #19.
This commit is contained in:
xuu
2024-01-01 09:26:31 -07:00
parent 378e403c1c
commit 86f2f7a6f2
7 changed files with 261 additions and 145 deletions

20
math.go
View File

@@ -3,19 +3,19 @@ package aoc
import "cmp"
type uinteger interface {
uint | uint8 | uint16 | uint32 | uint64
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
type sinteger interface {
int | int8 | int16 | int32 | int64
~int | ~int8 | ~int16 | ~int32 | ~int64
}
type integer interface {
sinteger | uinteger
}
// type float interface {
// complex64 | complex128 | float32 | float64
// }
// type number interface{ integer | float }
type float interface {
complex64 | complex128 | float32 | float64
}
type number interface{ integer | float }
// greatest common divisor (GCD) via Euclidean algorithm
func GCD[T integer](a, b T) T {
@@ -46,17 +46,17 @@ func LCM[T integer](integers ...T) T {
return result
}
func Sum[T integer](arr ...T) T {
func Sum[T number](arr ...T) T {
var acc T
for _, a := range arr {
acc += a
}
return acc
}
func SumFunc[T any, U integer](fn func(T) U, input ...T) U {
func SumFunc[T any, U number](fn func(T) U, input ...T) U {
return Sum(SliceMap(fn, input...)...)
}
func SumIFunc[T any, U integer](fn func(int, T) U, input ...T) U {
func SumIFunc[T any, U number](fn func(int, T) U, input ...T) U {
return Sum(SliceIMap(fn, input...)...)
}
@@ -71,7 +71,7 @@ func Power2(n int) int {
return p
}
func ABS(i int) int {
func ABS[I integer](i I) I {
if i < 0 {
return -i
}