mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
30 lines
456 B
Go
30 lines
456 B
Go
package one
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/onyx-and-iris/aoc2024/day-22/internal/randomiser"
|
|
)
|
|
|
|
const numIterations = 2000
|
|
|
|
func Solve(buf []byte) (int, error) {
|
|
r := bytes.NewReader(buf)
|
|
secrets, err := parseLines(r)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
var sum int
|
|
for _, secret := range secrets {
|
|
randomiser := randomiser.New(secret)
|
|
|
|
for range numIterations {
|
|
randomiser.Randomise()
|
|
}
|
|
sum += randomiser.Secret()
|
|
}
|
|
|
|
return sum, nil
|
|
}
|