mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
32 lines
518 B
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
|
|
}
|