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

32 lines
518 B
Go

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
}