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 }