Working on 2021 day 18

This commit is contained in:
2021-12-18 09:47:42 -06:00
parent 72be8f1ac5
commit 8a4a437947
5 changed files with 315 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
build := inp[0]
for _, v := range inp[1:] {
build = fmt.Sprintf("[%s,%s]", build, v)
}
// Keep on steppin' until no change happens
var wrk string
var done bool
for !done {
wrk = step(build)
done = wrk == build
build = wrk
}
fmt.Println(wrk)
}
var steps int
func step(inp string) string {
steps++
// Find the first number that needs to explode.
wrk := explode(inp)
if wrk != inp {
return wrk
}
// Nothing exploded, look for a split.
return split(inp)
}
func explode(inp string) string {
var depth int
for i := range inp {
if inp[i] == '[' {
if depth == 4 {
// Explode the leftmost pair from here
}
depth++
} else if inp[i] == ']' {
depth--
}
}
}
func split(inp string) string {
return inp
}