2023 Day 17 Complete
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
termbox "github.com/nsf/termbox-go"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
var gridWidth, gridHeight int
|
||||
@@ -18,8 +18,8 @@ func main() {
|
||||
passcode := "pvhmgsws"
|
||||
gridWidth, gridHeight = 4, 4
|
||||
if len(os.Args) >= 3 {
|
||||
gridWidth = aoc.Atoi(os.Args[1])
|
||||
gridHeight = aoc.Atoi(os.Args[2])
|
||||
gridWidth = h.Atoi(os.Args[1])
|
||||
gridHeight = h.Atoi(os.Args[2])
|
||||
}
|
||||
run := true
|
||||
err := termbox.Init()
|
||||
@@ -83,80 +83,80 @@ func PrintState(path, passcode string) {
|
||||
posX, posY := currPos(path)
|
||||
for y := 0; y < gridHeight; y++ {
|
||||
for x := 0; x < gridWidth; x++ {
|
||||
fmt.Print(aoc.BorderNW)
|
||||
fmt.Print(h.BorderNW)
|
||||
if posX == x && posY == y && doorIsOpen(path, passcode, 'N') {
|
||||
// Current Pos w/ open door
|
||||
fmt.Print(aoc.BorderSE)
|
||||
fmt.Print(aoc.BorderSW)
|
||||
fmt.Print(h.BorderSE)
|
||||
fmt.Print(h.BorderSW)
|
||||
} else if y == posY+1 && x == posX && doorIsOpen(path, passcode, 'S') {
|
||||
// Room below, w/ open door
|
||||
fmt.Print(aoc.BorderNE)
|
||||
fmt.Print(aoc.BorderNW)
|
||||
fmt.Print(h.BorderNE)
|
||||
fmt.Print(h.BorderNW)
|
||||
} else {
|
||||
// All other cases
|
||||
fmt.Print(aoc.BorderWE)
|
||||
fmt.Print(aoc.BorderWE)
|
||||
fmt.Print(h.BorderWE)
|
||||
fmt.Print(h.BorderWE)
|
||||
}
|
||||
fmt.Print(aoc.BorderNE)
|
||||
fmt.Print(h.BorderNE)
|
||||
}
|
||||
fmt.Println()
|
||||
for x := 0; x < gridWidth; x++ {
|
||||
if posX == x && posY == y && doorIsOpen(path, passcode, 'W') {
|
||||
fmt.Print(aoc.BorderSE)
|
||||
fmt.Print(h.BorderSE)
|
||||
} else {
|
||||
fmt.Print(aoc.BorderNS)
|
||||
fmt.Print(h.BorderNS)
|
||||
}
|
||||
if posX == x && posY == y {
|
||||
fmt.Print(aoc.BorderNW)
|
||||
fmt.Print(aoc.BorderNE)
|
||||
fmt.Print(h.BorderNW)
|
||||
fmt.Print(h.BorderNE)
|
||||
} else {
|
||||
fmt.Print(" ")
|
||||
fmt.Print(" ")
|
||||
}
|
||||
if posX == x && posY == y && doorIsOpen(path, passcode, 'E') {
|
||||
fmt.Print(aoc.BorderSW)
|
||||
fmt.Print(h.BorderSW)
|
||||
} else {
|
||||
fmt.Print(aoc.BorderNS)
|
||||
fmt.Print(h.BorderNS)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
for x := 0; x < gridWidth; x++ {
|
||||
if posX == x && posY == y && doorIsOpen(path, passcode, 'W') {
|
||||
fmt.Print(aoc.BorderNE)
|
||||
fmt.Print(h.BorderNE)
|
||||
} else {
|
||||
fmt.Print(aoc.BorderNS)
|
||||
fmt.Print(h.BorderNS)
|
||||
}
|
||||
if posX == x && posY == y {
|
||||
fmt.Print(aoc.BorderSW)
|
||||
fmt.Print(aoc.BorderSE)
|
||||
fmt.Print(h.BorderSW)
|
||||
fmt.Print(h.BorderSE)
|
||||
} else {
|
||||
fmt.Print(" ")
|
||||
fmt.Print(" ")
|
||||
}
|
||||
if posX == x && posY == y && doorIsOpen(path, passcode, 'E') {
|
||||
fmt.Print(aoc.BorderNW)
|
||||
fmt.Print(h.BorderNW)
|
||||
} else {
|
||||
fmt.Print(aoc.BorderNS)
|
||||
fmt.Print(h.BorderNS)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
for x := 0; x < gridWidth; x++ {
|
||||
fmt.Print(aoc.BorderSW)
|
||||
fmt.Print(h.BorderSW)
|
||||
if posX == x && posY == y && doorIsOpen(path, passcode, 'S') {
|
||||
fmt.Print(aoc.BorderNE)
|
||||
fmt.Print(aoc.BorderNW)
|
||||
fmt.Print(h.BorderNE)
|
||||
fmt.Print(h.BorderNW)
|
||||
} else {
|
||||
fmt.Print(aoc.BorderWE)
|
||||
fmt.Print(aoc.BorderWE)
|
||||
fmt.Print(h.BorderWE)
|
||||
fmt.Print(h.BorderWE)
|
||||
}
|
||||
fmt.Print(aoc.BorderSE)
|
||||
fmt.Print(h.BorderSE)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func ClearScreen() {
|
||||
fmt.Print(aoc.ClearScreen)
|
||||
fmt.Print(h.ClearScreen)
|
||||
}
|
||||
|
||||
func printUsageAndExit() {
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
var gridWidth, gridHeight int
|
||||
@@ -19,8 +19,8 @@ func main() {
|
||||
}
|
||||
passcode = os.Args[1]
|
||||
if len(os.Args) >= 4 {
|
||||
gridWidth = aoc.Atoi(os.Args[2])
|
||||
gridHeight = aoc.Atoi(os.Args[3])
|
||||
gridWidth = h.Atoi(os.Args[2])
|
||||
gridHeight = h.Atoi(os.Args[3])
|
||||
}
|
||||
foundPaths := findPaths("", passcode)
|
||||
if len(foundPaths) == 0 {
|
||||
|
@@ -5,15 +5,15 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Println("Usage: ./day18 <filename> <numrows>")
|
||||
}
|
||||
input := aoc.FileToBytes(os.Args[1])
|
||||
numRows := aoc.Atoi(os.Args[2])
|
||||
input := h.FileToBytes(os.Args[1])
|
||||
numRows := h.Atoi(os.Args[2])
|
||||
|
||||
room := [][]byte{input}
|
||||
for row := 1; row < numRows; row++ {
|
||||
|
@@ -3,14 +3,14 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
// pt1 input: 3014387
|
||||
func main() {
|
||||
partOne := aoc.ArgIsSet("-1")
|
||||
partOne := h.ArgIsSet("-1")
|
||||
num := 3014387
|
||||
if aoc.ArgIsSet("-test") {
|
||||
if h.ArgIsSet("-test") {
|
||||
num = 5 // Example
|
||||
}
|
||||
firstElf := CreateElf(1)
|
||||
|
@@ -6,18 +6,18 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
part1 := aoc.ArgIsSet("-1")
|
||||
justSort := aoc.ArgIsSet("-sort")
|
||||
input := aoc.StdinToStringSlice()
|
||||
part1 := h.ArgIsSet("-1")
|
||||
justSort := h.ArgIsSet("-sort")
|
||||
input := h.StdinToStringSlice()
|
||||
var blacklists []Blacklist
|
||||
for i := range input {
|
||||
pts := strings.Split(input[i], "-")
|
||||
st := aoc.Atoi(pts[0])
|
||||
end := aoc.Atoi(pts[1])
|
||||
st := h.Atoi(pts[0])
|
||||
end := h.Atoi(pts[1])
|
||||
blacklists = append(blacklists, *CreateBlacklist(st, end))
|
||||
}
|
||||
sort.Sort(ByStart(blacklists))
|
||||
|
@@ -4,13 +4,13 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
pw := "fbgdceah" // Part 2 Puzzle input
|
||||
input := aoc.StdinToStringSlice()
|
||||
if aoc.ArgIsSet("-1") {
|
||||
input := h.StdinToStringSlice()
|
||||
if h.ArgIsSet("-1") {
|
||||
pw = "abcdefgh" // Part 1 Puzzle input
|
||||
pw = scramblePassword(pw, input)
|
||||
fmt.Println(scramblePassword(pw, input))
|
||||
@@ -23,7 +23,7 @@ func unscramblePassword(pw string, inst []string) string {
|
||||
// Brute force it.
|
||||
// Just get all permutations of the runes and return the one
|
||||
// for which the instructions return the input
|
||||
tst := aoc.StringPermutations(pw)
|
||||
tst := h.StringPermutations(pw)
|
||||
for i := range tst {
|
||||
if scramblePassword(tst[i], inst) == pw {
|
||||
return tst[i]
|
||||
@@ -37,15 +37,15 @@ func scramblePassword(pw string, inst []string) string {
|
||||
pts := strings.Fields(inst[i])
|
||||
switch pts[0] + " " + pts[1] {
|
||||
case "swap position":
|
||||
pw = swapPos(pw, aoc.Atoi(pts[2]), aoc.Atoi(pts[5]))
|
||||
pw = swapPos(pw, h.Atoi(pts[2]), h.Atoi(pts[5]))
|
||||
case "swap letter":
|
||||
pw = swapLetter(pw, pts[2], pts[5])
|
||||
case "reverse positions":
|
||||
pw = reverse(pw, aoc.Atoi(pts[2]), aoc.Atoi(pts[4]))
|
||||
pw = reverse(pw, h.Atoi(pts[2]), h.Atoi(pts[4]))
|
||||
case "rotate left":
|
||||
pw = rotate(pw, aoc.Atoi(pts[2])*-1)
|
||||
pw = rotate(pw, h.Atoi(pts[2])*-1)
|
||||
case "rotate right":
|
||||
pw = rotate(pw, aoc.Atoi(pts[2]))
|
||||
pw = rotate(pw, h.Atoi(pts[2]))
|
||||
case "rotate based":
|
||||
rotIdx := strings.Index(pw, pts[6])
|
||||
if rotIdx >= 4 {
|
||||
@@ -54,7 +54,7 @@ func scramblePassword(pw string, inst []string) string {
|
||||
rotIdx++
|
||||
pw = rotate(pw, rotIdx)
|
||||
case "move position":
|
||||
pw = move(pw, aoc.Atoi(pts[2]), aoc.Atoi(pts[5]))
|
||||
pw = move(pw, h.Atoi(pts[2]), h.Atoi(pts[5]))
|
||||
}
|
||||
}
|
||||
return pw
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
"github.com/fatih/color"
|
||||
termbox "github.com/nsf/termbox-go"
|
||||
)
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func main() {
|
||||
var inpFn string
|
||||
var done bool
|
||||
if inpFn = aoc.GetArgNumber(1); inpFn != "" {
|
||||
if inpFn = h.GetArgNumber(1); inpFn != "" {
|
||||
done = true
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
var menuPos int
|
||||
cursor := color.New(color.FgBlack).Add(color.BgWhite)
|
||||
for !done {
|
||||
fmt.Println(aoc.ClearScreen)
|
||||
fmt.Println(h.ClearScreen)
|
||||
title := color.New(color.FgBlack).Add(color.BgYellow)
|
||||
title.Println(CenterText("day 22", tWidth))
|
||||
if menuPos == 0 {
|
||||
@@ -91,7 +91,7 @@ func main() {
|
||||
// Create the display
|
||||
d := CreateDisplay(tWidth, tHeight)
|
||||
if inpFn != "" {
|
||||
input := aoc.FileToStringSlice(inpFn)
|
||||
input := h.FileToStringSlice(inpFn)
|
||||
d.reset(CreateNodesFromInput(input))
|
||||
} else {
|
||||
d.reset(GenerateNodesForGrid(sizeX, sizeY))
|
||||
@@ -103,7 +103,7 @@ func main() {
|
||||
d.nodes[iToLoc(d.goalX, d.goalY)].Used = rand.Intn(75)
|
||||
}
|
||||
|
||||
if aoc.ArgIsSet("-1") {
|
||||
if h.ArgIsSet("-1") {
|
||||
var viablePairs []string
|
||||
for _, v1 := range d.nodes {
|
||||
for _, v2 := range d.nodes {
|
||||
@@ -119,7 +119,7 @@ func main() {
|
||||
done = false
|
||||
|
||||
for !done {
|
||||
fmt.Println(aoc.ClearScreen)
|
||||
fmt.Println(h.ClearScreen)
|
||||
d.PrintGrid()
|
||||
ev := termbox.PollEvent()
|
||||
if d.goalX == 0 && d.goalY == 0 {
|
||||
@@ -199,7 +199,7 @@ func CreateNodesFromInput(input []string) (map[string]*Node, int, int) {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
nodes[aoc.Itoa(n.X)+";"+aoc.Itoa(n.Y)] = n
|
||||
nodes[h.Itoa(n.X)+";"+h.Itoa(n.Y)] = n
|
||||
if n.X > maxX {
|
||||
maxX = n.X
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func (d *Display) PrintGrid() {
|
||||
}
|
||||
|
||||
func iToLoc(x, y int) string {
|
||||
return aoc.Itoa(x) + ";" + aoc.Itoa(y)
|
||||
return h.Itoa(x) + ";" + h.Itoa(y)
|
||||
}
|
||||
|
||||
func AddViablePair(a, b *Node, list []string) []string {
|
||||
@@ -503,23 +503,23 @@ func CreateNodeFromDfListing(inp string) (*Node, error) {
|
||||
n := new(Node)
|
||||
parseLoc := strings.Split(pts[0], "-")
|
||||
if parseLoc[1][0] == 'x' {
|
||||
n.X = aoc.Atoi(parseLoc[1][1:])
|
||||
n.X = h.Atoi(parseLoc[1][1:])
|
||||
}
|
||||
if parseLoc[2][0] == 'y' {
|
||||
n.Y = aoc.Atoi(parseLoc[2][1:])
|
||||
n.Y = h.Atoi(parseLoc[2][1:])
|
||||
}
|
||||
n.Size = aoc.Atoi(strings.TrimSuffix(pts[1], "T"))
|
||||
n.Used = aoc.Atoi(strings.TrimSuffix(pts[2], "T"))
|
||||
n.Size = h.Atoi(strings.TrimSuffix(pts[1], "T"))
|
||||
n.Used = h.Atoi(strings.TrimSuffix(pts[2], "T"))
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (n *Node) GetLocString() string {
|
||||
return aoc.Itoa(n.X) + ";" + aoc.Itoa(n.Y)
|
||||
return h.Itoa(n.X) + ";" + h.Itoa(n.Y)
|
||||
}
|
||||
|
||||
func (n *Node) ToString() string {
|
||||
return fmt.Sprint("[", n.GetLocString(), "](S:", aoc.Itoa(n.Size), ";A:", aoc.Itoa(n.Size-n.Used), ";U:", aoc.Itoa(n.Used), ")")
|
||||
return fmt.Sprint("[", n.GetLocString(), "](S:", h.Itoa(n.Size), ";A:", h.Itoa(n.Size-n.Used), ";U:", h.Itoa(n.Used), ")")
|
||||
}
|
||||
|
||||
func CenterText(txt string, width int) string {
|
||||
|
@@ -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()
|
||||
}
|
||||
|
||||
|
@@ -9,13 +9,13 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"../../"
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
var tWidth, tHeight int
|
||||
|
||||
func main() {
|
||||
fileNm := aoc.GetArgNumber(1)
|
||||
fileNm := h.GetArgNumber(1)
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Usage: ./day24 <mazefile>")
|
||||
os.Exit(1)
|
||||
@@ -32,14 +32,14 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
poiPerms := aoc.StringPermutations(poiString)
|
||||
poiPerms := h.StringPermutations(poiString)
|
||||
shortest := -1
|
||||
var shortestPerm string
|
||||
for _, perm := range poiPerms {
|
||||
if perm[0] != '0' {
|
||||
continue
|
||||
}
|
||||
if aoc.ArgIsSet("-2") {
|
||||
if h.ArgIsSet("-2") {
|
||||
// For part 2 we return to 0
|
||||
perm = perm + "0"
|
||||
}
|
||||
@@ -79,8 +79,8 @@ type Floor struct {
|
||||
|
||||
func CreateFloorFromFile(fileNm string) *Floor {
|
||||
f := new(Floor)
|
||||
f.debug = aoc.ArgIsSet("-d")
|
||||
f.cells = aoc.FileToStringSlice(fileNm)
|
||||
f.debug = h.ArgIsSet("-d")
|
||||
f.cells = h.FileToStringSlice(fileNm)
|
||||
for y := range f.cells {
|
||||
for x := range f.cells[y] {
|
||||
if f.cells[y][x] != '#' {
|
||||
@@ -101,7 +101,7 @@ func CreateFloorFromFile(fileNm string) *Floor {
|
||||
|
||||
// Find the shortest paths between all points of interest
|
||||
f.shortestPaths = make(map[string]int)
|
||||
if aoc.ArgIsSet("-2") {
|
||||
if h.ArgIsSet("-2") {
|
||||
|
||||
/* Output from running part 1
|
||||
1;2 232
|
||||
@@ -301,7 +301,7 @@ func (f *Floor) Solve(x, y, dist int) (Path, bool) {
|
||||
if !tPathContains {
|
||||
f.testedPath.Append(wrkCoord)
|
||||
if f.debug {
|
||||
fmt.Println(aoc.ClearScreen, f.start.Name(), "=>", f.end.Name(), "\n", len(f.testedPath.coords), "/", f.cellCount, "\n", "Shortest:", shortestFound)
|
||||
fmt.Println(h.ClearScreen, f.start.Name(), "=>", f.end.Name(), "\n", len(f.testedPath.coords), "/", f.cellCount, "\n", "Shortest:", shortestFound)
|
||||
f.PrintPath(f.testedPath)
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
}
|
||||
|
@@ -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()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user