refactoring

This commit is contained in:
Gabriel Bizdoc 2025-12-08 19:13:35 +02:00
parent bab511a9ee
commit 8cf000940c
No known key found for this signature in database
GPG Key ID: 3F0EDAECA5BE9ED9
2 changed files with 27 additions and 5 deletions

View File

@ -136,3 +136,25 @@ func (s *CustomScanner[T, K]) Scan() bool {
func (s *CustomScanner[T, K]) Err() error {
return s.err
}
type numeric interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
~float32 | ~float64
}
func Sum[T numeric](s []T) T {
var res T
for _, t := range s {
res += t
}
return res
}
func Prod[T numeric](s []T) T {
var res = T(1)
for _, t := range s {
res *= t
}
return res
}

View File

@ -3,17 +3,13 @@ package year25
import (
"bytes"
"fmt"
"log"
"os"
"strconv"
"strings"
"git.bizdoc.ro/gabi-public/Advent-of-Code.git/aoc"
"git.bizdoc.ro/private/devkit.git/collections/geometry/v2"
)
func Day6Part1(c aoc.Context) (int64, error) {
c.Logger = log.New(os.Stdout, "", log.LstdFlags)
lines, tokens, err := day6ParseInputs(c)
if err != nil {
return 0, fmt.Errorf("error parsing inputs: %w", err)
@ -48,7 +44,11 @@ func Day6Part2(c aoc.Context) (int64, error) {
for _, t := range tokens {
calc := day6NewCalc(t.Operation)
mask := geometry.NewGrid[byte](t.Size, len(lines)).Data()
mask := make([][]byte, t.Size)
for i := range t.Size {
mask[i] = make([]byte, len(lines))
}
for i := range mask {
for j := range mask[i] {
mask[i][j] = lines[j][t.Start+i]