2023 Day 17 Complete

This commit is contained in:
2023-12-17 10:52:08 -06:00
parent a34f05d1af
commit d64a18280f
16 changed files with 517 additions and 131 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/fatih/color"
termbox "github.com/nsf/termbox-go"
"../../"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
var regs = map[string]int{
@@ -30,17 +30,17 @@ func main() {
var debug bool
var inpFn string
var done bool
if inpFn = aoc.GetArgNumber(1); inpFn == "" {
if inpFn = h.GetArgNumber(1); inpFn == "" {
done = true
}
if inpFn != "" {
instructions = aoc.FileToStringSlice(inpFn)
instructions = h.FileToStringSlice(inpFn)
}
if aoc.ArgIsSet("-d") {
if h.ArgIsSet("-d") {
debug = true
}
if aoc.ArgIsSet("-p") {
if h.ArgIsSet("-p") {
pause = true
}
err := termbox.Init()
@@ -119,11 +119,11 @@ func main() {
// If we have a jnz c -2 it could be moving all of c into another register
v, ok := regs[ins[1]]
if !ok {
v = aoc.Atoi(ins[1])
v = h.Atoi(ins[1])
}
var p int
if p, ok = regs[ins[2]]; !ok {
p = aoc.Atoi(ins[2])
p = h.Atoi(ins[2])
}
if v != 0 {
// Subtract 1 from the jump because we incremented already
@@ -142,10 +142,10 @@ func main() {
}
var src1I, src2I int
if src1I, ok = regs[src1]; !ok {
src1I = aoc.Atoi(src1)
src1I = h.Atoi(src1)
}
if src2I, ok = regs[src2]; !ok {
src2I = aoc.Atoi(src2)
src2I = h.Atoi(src2)
}
regs[dst] = src1I * src2I
case "cpy":
@@ -161,7 +161,7 @@ func main() {
regs[dst] = v
} else {
// It's not, must be an int
regs[dst] = aoc.Atoi(src)
regs[dst] = h.Atoi(src)
}
case "inc":
if _, ok := regs[ins[1]]; !ok {
@@ -179,7 +179,7 @@ func main() {
if v, ok := regs[src]; ok {
srcI = v
} else {
srcI = aoc.Atoi(src)
srcI = h.Atoi(src)
}
srcI = curr + srcI
if srcI < 0 || srcI > len(instructions)-1 {
@@ -213,7 +213,7 @@ func main() {
// Fancy State Printing
func PrintState() {
fmt.Println(aoc.ClearScreen)
fmt.Println(h.ClearScreen)
PrintRegs()
}