refactoring
This commit is contained in:
parent
bab511a9ee
commit
8cf000940c
22
aoc/utils.go
22
aoc/utils.go
@ -136,3 +136,25 @@ func (s *CustomScanner[T, K]) Scan() bool {
|
|||||||
func (s *CustomScanner[T, K]) Err() error {
|
func (s *CustomScanner[T, K]) Err() error {
|
||||||
return s.err
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -3,17 +3,13 @@ package year25
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.bizdoc.ro/gabi-public/Advent-of-Code.git/aoc"
|
"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) {
|
func Day6Part1(c aoc.Context) (int64, error) {
|
||||||
c.Logger = log.New(os.Stdout, "", log.LstdFlags)
|
|
||||||
lines, tokens, err := day6ParseInputs(c)
|
lines, tokens, err := day6ParseInputs(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("error parsing inputs: %w", err)
|
return 0, fmt.Errorf("error parsing inputs: %w", err)
|
||||||
@ -48,7 +44,11 @@ func Day6Part2(c aoc.Context) (int64, error) {
|
|||||||
for _, t := range tokens {
|
for _, t := range tokens {
|
||||||
calc := day6NewCalc(t.Operation)
|
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 i := range mask {
|
||||||
for j := range mask[i] {
|
for j := range mask[i] {
|
||||||
mask[i][j] = lines[j][t.Start+i]
|
mask[i][j] = lines[j][t.Start+i]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user