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

@@ -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 {