2023 Day 17 Complete

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

View File

@ -7,7 +7,7 @@ import (
termbox "github.com/nsf/termbox-go" termbox "github.com/nsf/termbox-go"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
var gridWidth, gridHeight int var gridWidth, gridHeight int
@ -18,8 +18,8 @@ func main() {
passcode := "pvhmgsws" passcode := "pvhmgsws"
gridWidth, gridHeight = 4, 4 gridWidth, gridHeight = 4, 4
if len(os.Args) >= 3 { if len(os.Args) >= 3 {
gridWidth = aoc.Atoi(os.Args[1]) gridWidth = h.Atoi(os.Args[1])
gridHeight = aoc.Atoi(os.Args[2]) gridHeight = h.Atoi(os.Args[2])
} }
run := true run := true
err := termbox.Init() err := termbox.Init()
@ -83,80 +83,80 @@ func PrintState(path, passcode string) {
posX, posY := currPos(path) posX, posY := currPos(path)
for y := 0; y < gridHeight; y++ { for y := 0; y < gridHeight; y++ {
for x := 0; x < gridWidth; x++ { for x := 0; x < gridWidth; x++ {
fmt.Print(aoc.BorderNW) fmt.Print(h.BorderNW)
if posX == x && posY == y && doorIsOpen(path, passcode, 'N') { if posX == x && posY == y && doorIsOpen(path, passcode, 'N') {
// Current Pos w/ open door // Current Pos w/ open door
fmt.Print(aoc.BorderSE) fmt.Print(h.BorderSE)
fmt.Print(aoc.BorderSW) fmt.Print(h.BorderSW)
} else if y == posY+1 && x == posX && doorIsOpen(path, passcode, 'S') { } else if y == posY+1 && x == posX && doorIsOpen(path, passcode, 'S') {
// Room below, w/ open door // Room below, w/ open door
fmt.Print(aoc.BorderNE) fmt.Print(h.BorderNE)
fmt.Print(aoc.BorderNW) fmt.Print(h.BorderNW)
} else { } else {
// All other cases // All other cases
fmt.Print(aoc.BorderWE) fmt.Print(h.BorderWE)
fmt.Print(aoc.BorderWE) fmt.Print(h.BorderWE)
} }
fmt.Print(aoc.BorderNE) fmt.Print(h.BorderNE)
} }
fmt.Println() fmt.Println()
for x := 0; x < gridWidth; x++ { for x := 0; x < gridWidth; x++ {
if posX == x && posY == y && doorIsOpen(path, passcode, 'W') { if posX == x && posY == y && doorIsOpen(path, passcode, 'W') {
fmt.Print(aoc.BorderSE) fmt.Print(h.BorderSE)
} else { } else {
fmt.Print(aoc.BorderNS) fmt.Print(h.BorderNS)
} }
if posX == x && posY == y { if posX == x && posY == y {
fmt.Print(aoc.BorderNW) fmt.Print(h.BorderNW)
fmt.Print(aoc.BorderNE) fmt.Print(h.BorderNE)
} else { } else {
fmt.Print(" ") fmt.Print(" ")
fmt.Print(" ") fmt.Print(" ")
} }
if posX == x && posY == y && doorIsOpen(path, passcode, 'E') { if posX == x && posY == y && doorIsOpen(path, passcode, 'E') {
fmt.Print(aoc.BorderSW) fmt.Print(h.BorderSW)
} else { } else {
fmt.Print(aoc.BorderNS) fmt.Print(h.BorderNS)
} }
} }
fmt.Println() fmt.Println()
for x := 0; x < gridWidth; x++ { for x := 0; x < gridWidth; x++ {
if posX == x && posY == y && doorIsOpen(path, passcode, 'W') { if posX == x && posY == y && doorIsOpen(path, passcode, 'W') {
fmt.Print(aoc.BorderNE) fmt.Print(h.BorderNE)
} else { } else {
fmt.Print(aoc.BorderNS) fmt.Print(h.BorderNS)
} }
if posX == x && posY == y { if posX == x && posY == y {
fmt.Print(aoc.BorderSW) fmt.Print(h.BorderSW)
fmt.Print(aoc.BorderSE) fmt.Print(h.BorderSE)
} else { } else {
fmt.Print(" ") fmt.Print(" ")
fmt.Print(" ") fmt.Print(" ")
} }
if posX == x && posY == y && doorIsOpen(path, passcode, 'E') { if posX == x && posY == y && doorIsOpen(path, passcode, 'E') {
fmt.Print(aoc.BorderNW) fmt.Print(h.BorderNW)
} else { } else {
fmt.Print(aoc.BorderNS) fmt.Print(h.BorderNS)
} }
} }
fmt.Println() fmt.Println()
for x := 0; x < gridWidth; x++ { for x := 0; x < gridWidth; x++ {
fmt.Print(aoc.BorderSW) fmt.Print(h.BorderSW)
if posX == x && posY == y && doorIsOpen(path, passcode, 'S') { if posX == x && posY == y && doorIsOpen(path, passcode, 'S') {
fmt.Print(aoc.BorderNE) fmt.Print(h.BorderNE)
fmt.Print(aoc.BorderNW) fmt.Print(h.BorderNW)
} else { } else {
fmt.Print(aoc.BorderWE) fmt.Print(h.BorderWE)
fmt.Print(aoc.BorderWE) fmt.Print(h.BorderWE)
} }
fmt.Print(aoc.BorderSE) fmt.Print(h.BorderSE)
} }
fmt.Println() fmt.Println()
} }
} }
func ClearScreen() { func ClearScreen() {
fmt.Print(aoc.ClearScreen) fmt.Print(h.ClearScreen)
} }
func printUsageAndExit() { func printUsageAndExit() {

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
var gridWidth, gridHeight int var gridWidth, gridHeight int
@ -19,8 +19,8 @@ func main() {
} }
passcode = os.Args[1] passcode = os.Args[1]
if len(os.Args) >= 4 { if len(os.Args) >= 4 {
gridWidth = aoc.Atoi(os.Args[2]) gridWidth = h.Atoi(os.Args[2])
gridHeight = aoc.Atoi(os.Args[3]) gridHeight = h.Atoi(os.Args[3])
} }
foundPaths := findPaths("", passcode) foundPaths := findPaths("", passcode)
if len(foundPaths) == 0 { if len(foundPaths) == 0 {

View File

@ -5,15 +5,15 @@ import (
"fmt" "fmt"
"os" "os"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
func main() { func main() {
if len(os.Args) < 3 { if len(os.Args) < 3 {
fmt.Println("Usage: ./day18 <filename> <numrows>") fmt.Println("Usage: ./day18 <filename> <numrows>")
} }
input := aoc.FileToBytes(os.Args[1]) input := h.FileToBytes(os.Args[1])
numRows := aoc.Atoi(os.Args[2]) numRows := h.Atoi(os.Args[2])
room := [][]byte{input} room := [][]byte{input}
for row := 1; row < numRows; row++ { for row := 1; row < numRows; row++ {

View File

@ -3,14 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
// pt1 input: 3014387 // pt1 input: 3014387
func main() { func main() {
partOne := aoc.ArgIsSet("-1") partOne := h.ArgIsSet("-1")
num := 3014387 num := 3014387
if aoc.ArgIsSet("-test") { if h.ArgIsSet("-test") {
num = 5 // Example num = 5 // Example
} }
firstElf := CreateElf(1) firstElf := CreateElf(1)

View File

@ -6,18 +6,18 @@ import (
"sort" "sort"
"strings" "strings"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
func main() { func main() {
part1 := aoc.ArgIsSet("-1") part1 := h.ArgIsSet("-1")
justSort := aoc.ArgIsSet("-sort") justSort := h.ArgIsSet("-sort")
input := aoc.StdinToStringSlice() input := h.StdinToStringSlice()
var blacklists []Blacklist var blacklists []Blacklist
for i := range input { for i := range input {
pts := strings.Split(input[i], "-") pts := strings.Split(input[i], "-")
st := aoc.Atoi(pts[0]) st := h.Atoi(pts[0])
end := aoc.Atoi(pts[1]) end := h.Atoi(pts[1])
blacklists = append(blacklists, *CreateBlacklist(st, end)) blacklists = append(blacklists, *CreateBlacklist(st, end))
} }
sort.Sort(ByStart(blacklists)) sort.Sort(ByStart(blacklists))

View File

@ -4,13 +4,13 @@ import (
"fmt" "fmt"
"strings" "strings"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
func main() { func main() {
pw := "fbgdceah" // Part 2 Puzzle input pw := "fbgdceah" // Part 2 Puzzle input
input := aoc.StdinToStringSlice() input := h.StdinToStringSlice()
if aoc.ArgIsSet("-1") { if h.ArgIsSet("-1") {
pw = "abcdefgh" // Part 1 Puzzle input pw = "abcdefgh" // Part 1 Puzzle input
pw = scramblePassword(pw, input) pw = scramblePassword(pw, input)
fmt.Println(scramblePassword(pw, input)) fmt.Println(scramblePassword(pw, input))
@ -23,7 +23,7 @@ func unscramblePassword(pw string, inst []string) string {
// Brute force it. // Brute force it.
// Just get all permutations of the runes and return the one // Just get all permutations of the runes and return the one
// for which the instructions return the input // for which the instructions return the input
tst := aoc.StringPermutations(pw) tst := h.StringPermutations(pw)
for i := range tst { for i := range tst {
if scramblePassword(tst[i], inst) == pw { if scramblePassword(tst[i], inst) == pw {
return tst[i] return tst[i]
@ -37,15 +37,15 @@ func scramblePassword(pw string, inst []string) string {
pts := strings.Fields(inst[i]) pts := strings.Fields(inst[i])
switch pts[0] + " " + pts[1] { switch pts[0] + " " + pts[1] {
case "swap position": 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": case "swap letter":
pw = swapLetter(pw, pts[2], pts[5]) pw = swapLetter(pw, pts[2], pts[5])
case "reverse positions": 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": case "rotate left":
pw = rotate(pw, aoc.Atoi(pts[2])*-1) pw = rotate(pw, h.Atoi(pts[2])*-1)
case "rotate right": case "rotate right":
pw = rotate(pw, aoc.Atoi(pts[2])) pw = rotate(pw, h.Atoi(pts[2]))
case "rotate based": case "rotate based":
rotIdx := strings.Index(pw, pts[6]) rotIdx := strings.Index(pw, pts[6])
if rotIdx >= 4 { if rotIdx >= 4 {
@ -54,7 +54,7 @@ func scramblePassword(pw string, inst []string) string {
rotIdx++ rotIdx++
pw = rotate(pw, rotIdx) pw = rotate(pw, rotIdx)
case "move position": 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 return pw

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
"time" "time"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
"github.com/fatih/color" "github.com/fatih/color"
termbox "github.com/nsf/termbox-go" termbox "github.com/nsf/termbox-go"
) )
@ -16,7 +16,7 @@ import (
func main() { func main() {
var inpFn string var inpFn string
var done bool var done bool
if inpFn = aoc.GetArgNumber(1); inpFn != "" { if inpFn = h.GetArgNumber(1); inpFn != "" {
done = true done = true
} }
@ -30,7 +30,7 @@ func main() {
var menuPos int var menuPos int
cursor := color.New(color.FgBlack).Add(color.BgWhite) cursor := color.New(color.FgBlack).Add(color.BgWhite)
for !done { for !done {
fmt.Println(aoc.ClearScreen) fmt.Println(h.ClearScreen)
title := color.New(color.FgBlack).Add(color.BgYellow) title := color.New(color.FgBlack).Add(color.BgYellow)
title.Println(CenterText("day 22", tWidth)) title.Println(CenterText("day 22", tWidth))
if menuPos == 0 { if menuPos == 0 {
@ -91,7 +91,7 @@ func main() {
// Create the display // Create the display
d := CreateDisplay(tWidth, tHeight) d := CreateDisplay(tWidth, tHeight)
if inpFn != "" { if inpFn != "" {
input := aoc.FileToStringSlice(inpFn) input := h.FileToStringSlice(inpFn)
d.reset(CreateNodesFromInput(input)) d.reset(CreateNodesFromInput(input))
} else { } else {
d.reset(GenerateNodesForGrid(sizeX, sizeY)) d.reset(GenerateNodesForGrid(sizeX, sizeY))
@ -103,7 +103,7 @@ func main() {
d.nodes[iToLoc(d.goalX, d.goalY)].Used = rand.Intn(75) d.nodes[iToLoc(d.goalX, d.goalY)].Used = rand.Intn(75)
} }
if aoc.ArgIsSet("-1") { if h.ArgIsSet("-1") {
var viablePairs []string var viablePairs []string
for _, v1 := range d.nodes { for _, v1 := range d.nodes {
for _, v2 := range d.nodes { for _, v2 := range d.nodes {
@ -119,7 +119,7 @@ func main() {
done = false done = false
for !done { for !done {
fmt.Println(aoc.ClearScreen) fmt.Println(h.ClearScreen)
d.PrintGrid() d.PrintGrid()
ev := termbox.PollEvent() ev := termbox.PollEvent()
if d.goalX == 0 && d.goalY == 0 { if d.goalX == 0 && d.goalY == 0 {
@ -199,7 +199,7 @@ func CreateNodesFromInput(input []string) (map[string]*Node, int, int) {
fmt.Println(err) fmt.Println(err)
continue 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 { if n.X > maxX {
maxX = n.X maxX = n.X
} }
@ -456,7 +456,7 @@ func (d *Display) PrintGrid() {
} }
func iToLoc(x, y int) string { 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 { func AddViablePair(a, b *Node, list []string) []string {
@ -503,23 +503,23 @@ func CreateNodeFromDfListing(inp string) (*Node, error) {
n := new(Node) n := new(Node)
parseLoc := strings.Split(pts[0], "-") parseLoc := strings.Split(pts[0], "-")
if parseLoc[1][0] == 'x' { if parseLoc[1][0] == 'x' {
n.X = aoc.Atoi(parseLoc[1][1:]) n.X = h.Atoi(parseLoc[1][1:])
} }
if parseLoc[2][0] == 'y' { 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.Size = h.Atoi(strings.TrimSuffix(pts[1], "T"))
n.Used = aoc.Atoi(strings.TrimSuffix(pts[2], "T")) n.Used = h.Atoi(strings.TrimSuffix(pts[2], "T"))
return n, nil return n, nil
} }
func (n *Node) GetLocString() string { 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 { 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 { func CenterText(txt string, width int) string {

View File

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

View File

@ -9,13 +9,13 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
var tWidth, tHeight int var tWidth, tHeight int
func main() { func main() {
fileNm := aoc.GetArgNumber(1) fileNm := h.GetArgNumber(1)
if len(os.Args) < 2 { if len(os.Args) < 2 {
fmt.Println("Usage: ./day24 <mazefile>") fmt.Println("Usage: ./day24 <mazefile>")
os.Exit(1) os.Exit(1)
@ -32,14 +32,14 @@ func main() {
} }
} }
} }
poiPerms := aoc.StringPermutations(poiString) poiPerms := h.StringPermutations(poiString)
shortest := -1 shortest := -1
var shortestPerm string var shortestPerm string
for _, perm := range poiPerms { for _, perm := range poiPerms {
if perm[0] != '0' { if perm[0] != '0' {
continue continue
} }
if aoc.ArgIsSet("-2") { if h.ArgIsSet("-2") {
// For part 2 we return to 0 // For part 2 we return to 0
perm = perm + "0" perm = perm + "0"
} }
@ -79,8 +79,8 @@ type Floor struct {
func CreateFloorFromFile(fileNm string) *Floor { func CreateFloorFromFile(fileNm string) *Floor {
f := new(Floor) f := new(Floor)
f.debug = aoc.ArgIsSet("-d") f.debug = h.ArgIsSet("-d")
f.cells = aoc.FileToStringSlice(fileNm) f.cells = h.FileToStringSlice(fileNm)
for y := range f.cells { for y := range f.cells {
for x := range f.cells[y] { for x := range f.cells[y] {
if f.cells[y][x] != '#' { if f.cells[y][x] != '#' {
@ -101,7 +101,7 @@ func CreateFloorFromFile(fileNm string) *Floor {
// Find the shortest paths between all points of interest // Find the shortest paths between all points of interest
f.shortestPaths = make(map[string]int) f.shortestPaths = make(map[string]int)
if aoc.ArgIsSet("-2") { if h.ArgIsSet("-2") {
/* Output from running part 1 /* Output from running part 1
1;2 232 1;2 232
@ -301,7 +301,7 @@ func (f *Floor) Solve(x, y, dist int) (Path, bool) {
if !tPathContains { if !tPathContains {
f.testedPath.Append(wrkCoord) f.testedPath.Append(wrkCoord)
if f.debug { 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) f.PrintPath(f.testedPath)
time.Sleep(time.Millisecond * 50) time.Sleep(time.Millisecond * 50)
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
termbox "github.com/nsf/termbox-go" termbox "github.com/nsf/termbox-go"
"../../" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
var regs = map[string]int{ var regs = map[string]int{
@ -33,20 +33,20 @@ var outBuff string
// -25 Run day 25 simulation // -25 Run day 25 simulation
func main() { func main() {
var inpFn string var inpFn string
if inpFn = aoc.GetArgNumber(1); inpFn == "" { if inpFn = h.GetArgNumber(1); inpFn == "" {
done = true done = true
} }
if inpFn != "" { if inpFn != "" {
instructions = aoc.FileToStringSlice(inpFn) instructions = h.FileToStringSlice(inpFn)
} }
if aoc.ArgIsSet("-d") { if h.ArgIsSet("-d") {
debug = true debug = true
} }
if aoc.ArgIsSet("-p") { if h.ArgIsSet("-p") {
pause = true pause = true
} }
if aoc.ArgIsSet("-25") { if h.ArgIsSet("-25") {
// If running the day 25 simulation, ignore debug and pause flags // If running the day 25 simulation, ignore debug and pause flags
fmt.Println("Running Day 25 simulation, disabling debug & pause") fmt.Println("Running Day 25 simulation, disabling debug & pause")
debug = false debug = false
@ -65,7 +65,7 @@ func main() {
go readUserInput(eventChan) go readUserInput(eventChan)
go sendNoneEvent(eventChan) go sendNoneEvent(eventChan)
} }
if aoc.ArgIsSet("-25") { if h.ArgIsSet("-25") {
var day25Solved bool var day25Solved bool
regAStart := regs["a"] regAStart := regs["a"]
regBStart := regs["b"] regBStart := regs["b"]
@ -164,14 +164,14 @@ func ProcInstructions() {
if !ok { if !ok {
outBuff += ins[1] outBuff += ins[1]
} else { } 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 // This should be long enough for our day 25 answer
return return
} }
// If we're not debugging, just print it and reset the buffer // 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) fmt.Print(outBuff)
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 // If we have a jnz c -2 it could be moving all of c into another register
v, ok := regs[ins[1]] v, ok := regs[ins[1]]
if !ok { if !ok {
v = aoc.Atoi(ins[1]) v = h.Atoi(ins[1])
} }
var p int var p int
if p, ok = regs[ins[2]]; !ok { if p, ok = regs[ins[2]]; !ok {
p = aoc.Atoi(ins[2]) p = h.Atoi(ins[2])
} }
if v != 0 { if v != 0 {
// Subtract 1 from the jump because we incremented already // Subtract 1 from the jump because we incremented already
@ -202,10 +202,10 @@ func ProcInstructions() {
} }
var src1I, src2I int var src1I, src2I int
if src1I, ok = regs[src1]; !ok { if src1I, ok = regs[src1]; !ok {
src1I = aoc.Atoi(src1) src1I = h.Atoi(src1)
} }
if src2I, ok = regs[src2]; !ok { if src2I, ok = regs[src2]; !ok {
src2I = aoc.Atoi(src2) src2I = h.Atoi(src2)
} }
regs[dst] = src1I * src2I regs[dst] = src1I * src2I
case "cpy": case "cpy":
@ -221,7 +221,7 @@ func ProcInstructions() {
regs[dst] = v regs[dst] = v
} else { } else {
// It's not, must be an int // It's not, must be an int
regs[dst] = aoc.Atoi(src) regs[dst] = h.Atoi(src)
} }
case "inc": case "inc":
if _, ok := regs[ins[1]]; !ok { if _, ok := regs[ins[1]]; !ok {
@ -239,7 +239,7 @@ func ProcInstructions() {
if v, ok := regs[src]; ok { if v, ok := regs[src]; ok {
srcI = v srcI = v
} else { } else {
srcI = aoc.Atoi(src) srcI = h.Atoi(src)
} }
srcI = curr + srcI srcI = curr + srcI
if srcI < 0 || srcI > len(instructions)-1 { if srcI < 0 || srcI > len(instructions)-1 {
@ -270,7 +270,7 @@ func ProcInstructions() {
// Fancy State Printing // Fancy State Printing
func PrintState() { func PrintState() {
fmt.Println(aoc.ClearScreen) fmt.Println(h.ClearScreen)
PrintRegs() PrintRegs()
} }

141
2023/day17/input Normal file
View File

@ -0,0 +1,141 @@
131521531314413165554663355645644257613274614177575564515343675763343717733131466417431176612316451651616515743463261461663563523613444154252
254321311411454534466161643621353541657535174621665776157212576336534177224356633176673161736154621567774544771521656112526146345152542542144
551351111513441213121553332663651663461337267643135466575723446757536642575253255533424362727626726757571773547675755535113411643655666421155
432441114441634623124235621172721357265624163241322367515467653777221636524525344476227651326213614237251362626121272326365414252511244543235
123446644263133636563125442513327163531257754357124723174461274634486378448662787433262446144331424545356266752331761255666153254422331442312
445531164461411225156114224751735714616427722742152675535468555464266323232755552472777255653516754653257163141164722372651154162333652316333
342144656363316445422515743357366245625611741277741824258248645367823568263784886374334356656335213467665443136135333431646623365511355246456
552242522226252421251272356151666171264443651417744227455576525533885424286843432245373223424634724772576436333712761676744425361351245632312
612551451436464246322217334227753733547232667136642536657455822665788622252375362863766734462662722253271747771377641346653653415654244224661
353634434225211132116644241741437442465514222678864478678466525448527772774526335383726558467633287737752127763676562715531752215424315464342
211262235215333566414164677164434362344228654467842353645887736675532724265877647772354547825677646382537456437353641734264226136666534644435
533343166334146455664537412731425332573423823422777423632786544384636536253447666743784665378843644465827171724436345114652646734635516641633
143123132166633162271477311632743722677843628866743256554535447473822765536762465544586458248543657864675147373475472252544262622316551126552
332562532161613237422345157536347631248873425526288742323286432873728776732463455255258268268457875678284845331214174444512574776535662463532
245221445436116317321453527742355273752233262374487478544854368647687784763246268852475754382258272883644568427363264216524356364415645451246
264543412551657621637447174356572536667683464443827544447575824883472587527728326723628335774846256622433776533361432756433277152321124463512
613364515655656321551417635422654426673422652787485555452658228388545846585323553246358357634666575525256236586351257656764751163315255643534
435252225517227625163447742427648835382284587243867887833732445527774345547893884737537783337765433456784767872425614362473664111542112545544
225633616513222474673555542614286826263775267486775553772485846897789589597653799376452288678852788288336585438363347456322352412632643614132
654241553746415256745216112453885877373724675557524544347657774979337333965636458845393554432754543426628277745378341645442256777152643453121
216464644454265454532564473624788458283825688482328729675888995368379957858787885695586869742528385637235838856547866155415164775431432235554
622314657242364465565254745528228332727266425546547648695594689684387486798363494693848648473673727322462662585827826225211416135651164532256
114361346312663445432743886276387267674883665537446646989959663948435849757745834494533736563555433353683625435537845262516542765435346213443
422663644132375537643543877864767527248522473453569335759446368544846665344645434547945469746774555787268626732884624358436574642323324454325
226341577473112443162244586222845646847552753757788658649676733985497444849695535597535697496769844745485388734243222726643422534451373117513
215472262113561361133474334862723656256728456968496385844374433575895993449636658746788999898878788642658833734243343553485366621134175237562
565142545162432335553645537766844326326544996936664586998736684956767697854433548688773458483663436788884768568745888732227567142551411642364
363537234121663665278485344384667833682953653479696679589435458338545375954655673766548499774993495355372642826433385678662727353254461754734
335541163653142161323677583264278247276648946559958844436637587834838785785453679575468599674467395935957466645432833573742617126172416334134
317563475422251172574344727256677577634368344447864944547668836567796686494873693878458439893745998933358384886328436556234854222565272711172
316443612746646713488784247722333786548887667668668375357656957583856756587658999343856557595585569646497874248866752358752586657245363566651
742665262276145343647875365366373759474785987498366383695555835466747866464789467865974867958553355899576384824455556673824742521333347142314
271521715675114643658577252753763839567865435357557853379778854559884856689986466648878877765799635783987858442278436524688655834615546116353
363573516327262688343535534742722436488657749977985535337974556878665767764775556869495596555863845588534335376337528372644428775517625556422
232647476772633645537644768225876674836684698367944857887884659565976886477658474569759887987398398874853799789462835538738726246523162623531
712345444646653567657745553844267657744569954634454987657989897475868984847698797878498688487683659486867554879933545253452883652655562347221
676716513661688827573886668724459838494548389948787896567578798978856857544987867578846496658639995958553668356364665686272442424272656656657
714563243744275258674484426359669765395947843863878796986697547794576579979975645567454857577554393875499974684438882383374554827715172245661
733763641216248357287546438575537339337499676434569898845474695987468764777467855984966594595874874379463878784649555685865384558224476466154
122175543158336566874662376748875735649973573568764778997779598477757954954989574988458759895664873595565466734638458242528226373785336362332
245463144775558287534254833967339637358996933885979587889679775584578679985649568594778984475647786589339893958684896754458774228456276124214
757612743438282725557758249659766865595469939647467989945445479469546689454749664876785468576657476748836896895495389332624867288477646413323
722153352662427622347825239359449948757556785558599957977767664969767684645569474796798845687576658859457333933675993868425865252888546676647
655172344678257853883425794755679953849744849664489954896778589796459746486799656484979458684865894847475668889686433438764443366244261232656
162462531888742232875488866567767735336657446789967885546767765569585585878985767889455874674468459445785486694798397497526632722477644716674
242353233478824387537334694964738445464895475449878565488667855989766885785769795776765474768476484745794459435747853436273875878743561414273
664715236735588465352229986888373699885574789677658545769846568966867885877995586767979548665677664568549576557445648664254888466854277667242
543247622573868422872537474863958775877598674769697974668449687667558969788666997786786869848457465497697785358657948738362436233685734315554
635516668624276843427654786688543776684996669666697956564987777575865967656995798565886787774789776765488694666845946886733754223688463413553
726244332658246283737747437649883848645896958587858488488759757659759969996765866688768677694488444695566738883396794664936528228532658437224
663731384784678252356373539867557655666699595956579948955789958697957596756576667998567798699447466798745658593579786357767864226285742524715
565543444788663227462389697377874577598877984677568875797858597576985768598888865975896867694694759778745854749639556798552872656625468332424
153325656864776582846465377559367577978448769955584455558579677685565899578959668779659876588759985648747757838633694863485344474248856336147
536374735686762633228836739769564699869444449969458785996557789755858578789998789787965675666559568745865685583834839873854687685782833264465
774773863338734283336634947736939687769749974559698998679767795785577765976587565996955867668799798958846855669795737335876224468444826256472
561224576433232354749483886455637689857478557877876957565568697695866678969967867657585885996576756596686797737676679646538976386738738427143
235423764823584788654934486537698565489955588954976667585596656788875797968796857776859586868969856864975997484565485574654937683756838425314
356477878377755324746474936736734765775944656889979598757585665579988868799587786686987889999954784888846786659879456499857676766658364866753
343463783884548723286545357959568655898755558749578868987898867769887798668886657878966685585885668747654655793867948788339943682533437444137
721478685435244783563943339558694757886457669789697856685986698867789767866867979556565568697688865648746878596489456635983877677674485374171
571274872383884835338375798745369969446445489957855578566598965887866686677979698758798578656968596694987675665346765639936774526235864842312
441162566683346665976974596739867576945789746989695588986669597898777886896667878896898577889768599888898448859847695959545537275537742543517
267273334848287463887834665984947565779488854497557959988776897989977987897769799958958557699565659598864695454874464988445866643562383728822
333585242832838557448544874996398588955749757579685868796887867668869986779889877699696668696576987499756846796678897438365733268448387837721
624624724588444535778636655556385686555489455587596795598798767879688886967678969989885766769575676664769584868838379469448882456427437777332
342445435623444563383969633857884555985997485885867978775986976967968698796787996786679957595899965476678768666683843937378788782733578487321
171185248322547583488847338593699554579744765766575797879786987768889898996768777887559768556756557579795467984847459833787935483868664264773
665282632778825737797689495978874748644998956778688759896567668687999968787686976977767567897598859569489957976776537883676394557585642877876
612255333377233543738586964773677457874877976785558895967667688869697999869987889779766795859986769997956764857457399589734398852568546223566
145468486222328253765834868956445954658785665567789998677578978967768888789796879967657677975989899779994567596986444576439838758342622674675
555688565735352444387589856376789895994955498575598696587667686689787969898769968887688777589856878548899475899848464896567563534547227635345
677357723425675467383579757799699445867568477577776778556968678987879967787797769666895986598586686566869497454747434678938653233363355767461
343568483385257574437438757565798657995855788787667787666586899979878689678896999866789755567799675797994955697746859968484855277436486656863
326676886762328437836595893999567966488576559585666695655786686668789778666678988899669778586599855669448889967578995874367875348545575623764
371243428277463637346789636578988747995849649857879666899777979767767969986798966877787568889568986675556557599443776345574776687868823538237
775225382257568444896473954597499889489678766996589796897587687696779788869689887969765677796965979998644748696659877944538995664453245745713
523343358253743468855658847849676597847985889578575766666676888787997699677979768669885756567697874758486656665473877443653899687667264868855
643427332753365463837574885546597597755855654586897959668986898667798888678896796699959955889986798679454988485997555546787977648856858585453
157342282823457268346378938388974764988879978957558856695866676988996686767689779869956556977665976586498675447644453988974534488672853367323
547125787522487233446878759439477697767787846798666958759687899996689977787677789965696767755676898966587989946453634444666443827537356357417
254287473232444758783646563945637468497764944967676877758786777776678777999779868676899678798678966968784894867483584376854346357755777563615
554165726834468847535767685943965566857765445598565867696858658996879668998866798768899888859897874968669766487856396858488843252335428574614
265285777545335665856578776754396844479984767788998866565659786999798777669678689998685879787887599644555497887434356499347564847486545377875
463447737288846887363964563767956566946794698768668666769679578988998899969678586985567767778955776756878594555989946545637498337328336528445
261518474486245283833345487479573584778948758558599568687687999996676777776986987865888665999697747687685676543856553663387534734242786656752
635147647263678582663677689884565577447959675688756965867568785969765596768896876857899567677776476744778565664837479835966876435584855438552
557545647383765527296379893848895364766854766956796555688659956855796759999596766658696675989774894459968947945477557797753356627275437576451
543613286777256843584479776587398679479495546678668986866986855957767899859988796879867776658587798994898995978838665698356774475837726654322
223747357427768788726395498953637395998687499976578559569769889997698957679869997955867766796898475858794587465646695333696855243452683736543
126324266572355663683783669856569476689944857466884765857857875856795595985967969598877985794798546547858686499398878366738824633334545353453
546666463268542254564365887733579495856749598984795479966977865897768755888587558999658677549659449777795578449457849378766454458867278271227
766752328754236626825668547473844463764845755776958546666756868655758798865789867687567887978787756847765974397953956534658853274835487783462
242677674625253274522576448565877645475794967467644589787797859877587756656978975956886685698466965448779444446545893659997624427427366615475
113662224244372372723544453597458793589944555979549497565696995966568989586766599677665765465496454968884796765336693367488383663774673225145
575753446257728322467895394765459734835575565857565556957777858769597798698895589886557775975798844849656389393863863653822634747827238847223
554153776364424272764426774777676399395977866559474947589787766985557798697567965669585986854884874859855975796588655668377373286357252631174
555244763773384488245347597965877633475846965565669789948477957598756895566668756799644955744869477656793878566746333758727886248265737755636
511462132578858542236436694355554578853676445945997856448748646899858985975889799764955695567987556696765498687994989485246856478225226172574
275522616565387258763578345996978993475499849674694598656845856795646869668446678689766596496445744674663453464586648878862754265574666522577
152232356188688367332425688887946773766664879784577748499596475457559886994487644798444876998656679775788534663736654882763484835227353553552
343737252228848383547477776879538447646893689884654494766899888495969754648886475844946555787879559474637685898974749922727287538454657662127
252444474342645787874645678965753334547888458997778966874954579854765887658996699685459868868458666559539833535573898283343553387556441336344
661712736574455876442864833846745865373967699557884867878495455977664559769564685785946565879496566737795635655388673547286326747723266741762
124475116337557533256422835966367476894597469386954895876566479988545986749687449979467764988656869958474577447939556788882768256347462315262
433454471737233374643548238449498658585479737886789557866555557994798898984866578795977485555486738583769934337569936326823442525561326461611
541231543366377387642534526457768773693478939465647847475465956969675584576978697874498447487653936799635695638539237628842758573363364244756
354573425252154245356873543836883355547477563889744546987574889667989448946668788587978774543397963683688469577976737356647553282474174674151
123154734516772566258276348725837979558866478339588375595485665487756598459756756559668594798785797874467336535727737826742885867162342472512
367165651276364244327676365568854845666585644859436767787796599864858776777688768799756558857583836585499836558266527458775282767233672416425
132441731572413583234527458865658456647337674533938985874577755957494878486467547947466894954774446357849745853473765858765555255214464653375
527164715264551736546338555422635575676478986439679383734844668588747986795666449789565886678865737536568958464638652557862585234773135623445
473625123377214358878243625673256488348333495557483884763439858994688677498647866993585698378848534737439995367485285762367328326667534657353
442431532514243627534484657636227557597479944895477544977854758949496884876898434768476364673385596964499868377222553456365768461255361637556
317412461772761314567546567654427564785793459547789685685974586963888446554335985878447366867467589477966467757732535883765647534613145447772
512136722424557276145657582267746274227834668466739475373867455447374536859737564594494665577387449448853887772628866435788562116752661565155
144234437532544772134645682624352477248643747445769465349587673673336359744776597669846434537747639598447388383752557562274543565773514217133
325635414524451217564245676352236365566675749543883949339788349878373376599496397478966888394567948966275457287763373827273665447166371675612
556154253526567771363435622544437723757534733538439833588595636596697579886753895644834987678939483933222572577226437654783437451171637775125
146242634575476636116238468742337248338788458676785667697553797987569747374585795697993473487974964282367753483257442868853154734626741552414
316567527457122337416542227424577337725326464774345975345636936557445489875643739488559958667897955363647853337622776748152761514333462723411
253216352444247441363736244682682354248766426652678476733789594788465357889577799784787449938544382835352547757743333653561221641643142664615
143115265131671266253721675324423667877248338226389557398987356973334465745985434633884755449483432882474524457362348465717213534237666625533
463225654541344717346262573758663336456256826757585843589995367637476393738379948886967996358527477574237657666784758714425324234117237352565
533523555534463145375222277172236865722364656362632534663876464694566536999879476635973874373255565572677347453564347524677422257275651444426
422162111612337777416173771154677237664625775282324875872666889397344535997987459739587634844273627475287638837524256515614712273677671341252
145411356257217722114476717424533622534725643655474468486445468486885583679699373745455657345888562844625266632247472227623745663743213161456
152156654514233422146645176572565685848857838673588635535356454663432632654455727677678372668756463276686647242555514673313476523656262253266
666225453426565773663762227144571324234858554658757324475233483728657547687586582866757272587762554347556866346244441234521463655765431325112
511136633534477724515111652715427375553642345842856457656822754425558468564583645677625385235535786884524528821133653335352326527734465231526
143535341544163716473632713155753265747373874644725765653344348325252663478358388724827777857577282347634877163212333457436166276366611442254
365452251135242173735434344453537644726734378234684827753877243545634427522263888664277234483544762567626131764654166452231277175236243534344
265453353544244422172733513775235334637648856626634275787777587627864637732435678645678782253242484665451212361246275361646767613351126113446
351164446164565347672555143725344133531222564256383333367347623324758686528454442638622425287467732385154477324351617527514553341336614326625
635525653613153621765576657622261763533272712364863262354784862876832466546357488887572853834832568215625715673763361425345326112126513625516
133546455652256514234762455172227653166374752224866336348537424423232625226758824725835275754788667315776773644162434677276544214535143452133
546433443346524662342141452141156551252777472141825222882733566325672334348754852647687568528621175561161645225665547711254124642313355256531
512246346516263262156146252342456171731225451121711833732673568377675737344646365233227875382243112522526235726547133736551446244145652645315
333554234526135462565532526655616427174352422567454241226847482647684775336284762663226662331434356142117754376611323415141226611346542541342
132233616631113614415163246465561151235211615722654454661763477364446875527263226337724654417171457672576522165442766724162511413346523112141
415524312615655662311343327662346226346475442247556767434567325742333762626637153121541617253443571674174324232543472364252353664523655562344
315122331212345234666316461662714174774112716446152344247762426533263122662171731364456714145662776273426434357543316152365314263542426365135

247
2023/day17/main.go Normal file
View File

@ -0,0 +1,247 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(input []string) {
m := h.StringSliceToCoordByteMap(input)
fmt.Println("# Part 1")
fmt.Println(solve(&m, 0, 3))
}
// 1188 is too low
func part2(input []string) {
m := h.StringSliceToCoordByteMap(input)
fmt.Println("# Part 2")
fmt.Println(solve(&m, 4, 10))
}
func solve(m *h.CoordByteMap, minStraight, maxStraight int) int {
q := NewPriorityQueue[heatState](func(a, b heatState) int {
return a.heatLoss - b.heatLoss
})
q.Push(heatState{
state: state{
pos: &h.Coordinate{X: m.TLX + 1, Y: m.TLY},
dir: dirE,
dirCount: 1,
},
})
q.Push(heatState{
state: state{
pos: &h.Coordinate{X: m.TLX, Y: m.TLY + 1},
dir: dirS,
dirCount: 1,
},
})
end := h.Coordinate{X: m.BRX, Y: m.BRY}
visitedCoords := make(map[h.Coordinate]bool)
visited := make(map[string]int)
for q.IsNotEmpty() {
chk := q.Pop()
if !m.ContainsCoord(*chk.state.pos) {
continue
}
heat := int(m.Get(*chk.state.pos)-'0') + chk.heatLoss
if chk.state.pos.Equals(end) && chk.dirCount >= minStraight {
return heat
}
if visHeat, ok := visited[chk.state.String()]; ok {
if visHeat <= heat {
continue
}
}
visitedCoords[*chk.state.pos] = true
visited[chk.state.String()] = heat
if chk.dirCount >= minStraight {
// Add Left Turn
left := chk.dir.LeftTurn().Get(chk.pos)
if m.ContainsCoord(*left) {
q.Push(heatState{
state: state{
pos: left,
dir: chk.dir.LeftTurn(),
dirCount: 1,
},
heatLoss: heat,
})
}
// Add Right Turn
right := chk.dir.RightTurn().Get(chk.pos)
if m.ContainsCoord(*right) {
q.Push(heatState{
state: state{
pos: right,
dir: chk.dir.RightTurn(),
dirCount: 1,
},
heatLoss: heat,
})
}
}
if chk.dirCount < maxStraight {
// Add Straight
straight := chk.dir.Get(chk.pos)
if m.ContainsCoord(*straight) {
q.Push(heatState{
state: state{
pos: straight,
dir: chk.dir,
dirCount: chk.dirCount + 1,
},
heatLoss: heat,
})
}
}
}
return h.MAX_INT
}
type state struct {
pos *h.Coordinate
dir direction
dirCount int
}
func (s state) String() string {
return fmt.Sprintf("%s-%s-%d", s.pos, s.dir, s.dirCount)
}
type heatState struct {
state
heatLoss int
}
type PriorityQueue[T comparable] struct {
items []T
comparator func(a, b T) int
}
func NewPriorityQueue[T comparable](comparator func(a, b T) int) PriorityQueue[T] {
return PriorityQueue[T]{comparator: comparator}
}
func (pq *PriorityQueue[T]) Push(item T) {
pq.items = append(pq.items, item)
pq.heapifyUp(len(pq.items) - 1)
}
func (pq *PriorityQueue[T]) Pop() T {
top := pq.items[0]
lastIndex := len(pq.items) - 1
pq.items[0], pq.items[lastIndex] = pq.items[lastIndex], pq.items[0]
pq.items = pq.items[:lastIndex]
pq.heapifyDown(0)
return top
}
func (pq *PriorityQueue[T]) Peek() T {
return pq.items[0]
}
func (pq *PriorityQueue[T]) Len() int {
return len(pq.items)
}
func (pq *PriorityQueue[T]) IsEmpty() bool {
return len(pq.items) == 0
}
func (pq *PriorityQueue[T]) IsNotEmpty() bool {
return !pq.IsEmpty()
}
func (pq *PriorityQueue[T]) heapifyUp(index int) {
for index > 0 {
parentIndex := (index - 1) / 2
if pq.comparator(pq.items[index], pq.items[parentIndex]) < 0 {
pq.items[index], pq.items[parentIndex] = pq.items[parentIndex], pq.items[index]
index = parentIndex
} else {
break
}
}
}
func (pq *PriorityQueue[T]) heapifyDown(index int) {
for {
leftChild, rightChild, smallest := 2*index+1, 2*index+2, index
if leftChild < len(pq.items) && pq.comparator(pq.items[leftChild], pq.items[smallest]) < 0 {
smallest = leftChild
}
if rightChild < len(pq.items) && pq.comparator(pq.items[rightChild], pq.items[smallest]) < 0 {
smallest = rightChild
}
if smallest != index {
pq.items[index], pq.items[smallest] = pq.items[smallest], pq.items[index]
index = smallest
} else {
break
}
}
}
type direction h.Coordinate
func (d direction) Get(from *h.Coordinate) *h.Coordinate {
switch d.String() {
case "N":
return from.GetNorthCoord()
case "E":
return from.GetEastCoord()
case "S":
return from.GetSouthCoord()
case "W":
return from.GetWestCoord()
}
return from
}
func (d direction) LeftTurn() direction {
switch d.String() {
case "N":
return dirW
case "E":
return dirN
case "S":
return dirE
default:
return dirS
}
}
func (d direction) RightTurn() direction {
switch d.String() {
case "N":
return dirE
case "E":
return dirS
case "S":
return dirW
default:
return dirN
}
}
func (d direction) String() string {
switch {
case d.X == dirN.X && d.Y == dirN.Y:
return "N"
case d.X == dirE.X && d.Y == dirE.Y:
return "E"
case d.X == dirS.X && d.Y == dirS.Y:
return "S"
default:
return "W"
}
}
var (
dirN = direction{X: 0, Y: -1}
dirE = direction{X: 1, Y: 0}
dirS = direction{X: 0, Y: 1}
dirW = direction{X: -1, Y: 0}
)

13
2023/day17/testinput Normal file
View File

@ -0,0 +1,13 @@
2413432311323
3215453535623
3255245654254
3446585845452
4546657867536
1438598798454
4457876987766
3637877979653
4654967986887
4564679986453
1224686865563
2546548887735
4322674655533

5
2023/day17/testinput2 Normal file
View File

@ -0,0 +1,5 @@
111111111111
999999999991
999999999991
999999999991
999999999991

8
go.mod
View File

@ -1,6 +1,6 @@
module git.bullercodeworks.com/brian/adventofcode module git.bullercodeworks.com/brian/adventofcode
go 1.16 go 1.20
require ( require (
github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6 github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6
@ -8,8 +8,12 @@ require (
github.com/fatih/color v1.7.0 github.com/fatih/color v1.7.0
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72 github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317
)
require (
github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 golang.org/x/sys v0.0.0-20191008105621-543471e840be // indirect
) )

24
go.sum
View File

@ -1,27 +1,13 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6 h1:QaQWdi0Kgk1v+DW35aaBsEpoig3smyjJy2M6e/dePjM= github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6 h1:QaQWdi0Kgk1v+DW35aaBsEpoig3smyjJy2M6e/dePjM=
github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6/go.mod h1:g8Iv1LnV2Dg45Bg5uCATrYi5Y57mXWsqlPnfU2BhD5I= github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6/go.mod h1:g8Iv1LnV2Dg45Bg5uCATrYi5Y57mXWsqlPnfU2BhD5I=
github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca h1:UMJCb+zIdrTX68nP5byq1xjW72UIqMBNxcYPlPFhnOs= github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca h1:UMJCb+zIdrTX68nP5byq1xjW72UIqMBNxcYPlPFhnOs=
github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca/go.mod h1:x9wJlgOj74OFTOBwXOuO8pBguW37EgYNx51Dbjkfzo4= github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca/go.mod h1:x9wJlgOj74OFTOBwXOuO8pBguW37EgYNx51Dbjkfzo4=
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2 h1:H/prDPxUZBsK4DQC7ScP3ftSijMtWyetb6ab69DSKrs=
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2/go.mod h1:lMy7txIyYXt+I/1JgTGBZTdyTNJyNVDCX4Z+lHzNcSM=
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da h1:hjpZV7G49m1bly++F+Gho1Sbf2+eBW/eTLJWuRkH9Uc=
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da/go.mod h1:dywSSi3sMtJn2IjiYfJciP9tjVVeIVRa7AE7N5WLUBo=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw= github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72 h1:LgLYrxDRSVv3kStk6louYTP1ekZ6t7HZY/X05KUyaeM= github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72 h1:LgLYrxDRSVv3kStk6louYTP1ekZ6t7HZY/X05KUyaeM=
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 h1:EFT6MH3igZK/dIVqgGbTqWVvkZ7wJ5iGN03SVtvvdd8=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25/go.mod h1:sWkGw/wsaHtRsT9zGQ/WyJCotGWG/Anow/9hsAcBWRw=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
@ -29,18 +15,8 @@ github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW1
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975 h1:zm/Rb2OsnLWCY88Njoqgo4X6yt/lx3oBNWhepX0AOMU=
github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975/go.mod h1:4Mct/lWCFf1jzQTTAaWtOI7sXqmG+wBeiBfT4CxoaJk=
github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 h1:hhGN4SFXgXo61Q4Sjj/X9sBjyeSa2kdpaOzCO+8EVQw= github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 h1:hhGN4SFXgXo61Q4Sjj/X9sBjyeSa2kdpaOzCO+8EVQw=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU= golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=