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{
@@ -33,20 +33,20 @@ var outBuff string
// -25 Run day 25 simulation
func main() {
var inpFn string
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
}
if aoc.ArgIsSet("-25") {
if h.ArgIsSet("-25") {
// If running the day 25 simulation, ignore debug and pause flags
fmt.Println("Running Day 25 simulation, disabling debug & pause")
debug = false
@@ -65,7 +65,7 @@ func main() {
go readUserInput(eventChan)
go sendNoneEvent(eventChan)
}
if aoc.ArgIsSet("-25") {
if h.ArgIsSet("-25") {
var day25Solved bool
regAStart := regs["a"]
regBStart := regs["b"]
@@ -164,14 +164,14 @@ func ProcInstructions() {
if !ok {
outBuff += ins[1]
} else {
outBuff += aoc.Itoa(v)
outBuff += h.Itoa(v)
}
if aoc.ArgIsSet("-25") && len(outBuff) == 10 {
if h.ArgIsSet("-25") && len(outBuff) == 10 {
// This should be long enough for our day 25 answer
return
}
// If we're not debugging, just print it and reset the buffer
if !debug && !aoc.ArgIsSet("-25") {
if !debug && !h.ArgIsSet("-25") {
fmt.Print(outBuff)
outBuff = ""
}
@@ -179,11 +179,11 @@ func ProcInstructions() {
// 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
@@ -202,10 +202,10 @@ func ProcInstructions() {
}
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":
@@ -221,7 +221,7 @@ func ProcInstructions() {
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 {
@@ -239,7 +239,7 @@ func ProcInstructions() {
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 {
@@ -270,7 +270,7 @@ func ProcInstructions() {
// Fancy State Printing
func PrintState() {
fmt.Println(aoc.ClearScreen)
fmt.Println(h.ClearScreen)
PrintRegs()
}