aoc2024/day-17/internal/one/solve.go

32 lines
518 B
Go
Raw Permalink Normal View History

2024-12-18 15:02:35 +00:00
package one
import (
"bytes"
"strconv"
"strings"
)
type operand int
type instructionFn func(operand) (int, bool, int, bool)
func Solve(buf []byte) (string, error) {
r := bytes.NewReader(buf)
registers, program, err := parseLines(r)
if err != nil {
return "", err
}
computer := newComputer(registers)
results := computer.run(program)
var sb strings.Builder
for i, n := range results {
sb.WriteString(strconv.Itoa(n))
if i < len(results)-1 {
sb.WriteRune(',')
}
}
return sb.String(), nil
}