chore: add day16
All checks were successful
Go Bump / bump (push) Successful in 6s
Go Test / build (push) Successful in 34s

This commit is contained in:
xuu 2023-12-16 12:43:17 -07:00
parent b97ecdc93c
commit e742db7ec9
Signed by: xuu
GPG Key ID: 8B3B0604F164E04F

View File

@ -2,6 +2,7 @@ package aoc
import (
"bufio"
"cmp"
"fmt"
"os"
"path/filepath"
@ -88,13 +89,7 @@ func LCM[T integer](integers ...T) T {
}
func ReadStringToInts(fields []string) []int {
arr := make([]int, len(fields))
for i, s := range fields {
if v, err := strconv.Atoi(s); err == nil {
arr[i] = v
}
}
return arr
return SliceMap(Atoi, fields...)
}
type Node[T any] struct {
@ -214,8 +209,8 @@ func Atoi(s string) int {
return i
}
func Repeat(s string, i int) []string {
lis := make([]string, i)
func Repeat[T any](s T, i int) []T {
lis := make([]T, i)
for i := range lis {
lis[i] = s
}
@ -237,6 +232,9 @@ func SumIFunc[T any,U integer](fn func(int, T) U, input ...T) U {
}
func Power2(n int) int {
if n == 0 {
return 1
}
p := 2
for ; n > 1; n-- {
p *= 2
@ -273,3 +271,20 @@ func Reduce[T, U any](fn func(int, T, U) U, u U, list ...T) U {
}
return u
}
func Max[T cmp.Ordered](a T, v ...T) T {
for _, b := range v {
if b > a {
a = b
}
}
return a
}
func Min[T cmp.Ordered](a T, v ...T) T {
for _, b := range v {
if b < a {
a = b
}
}
return a
}