package main import ( "fmt" "strings" h "git.bullercodeworks.com/brian/adventofcode/helpers" ) func main() { inp := h.StdinToStringSlice() solve(1, inp) fmt.Println("") solve(2, inp) } type pair struct { first int second int } func solve(part int, inp []string) { var model [14]int var stack []pair for i := 0; i < 14; i++ { xAdd := h.Atoi(strings.Fields(inp[18*i+5])[2]) yAdd := h.Atoi(strings.Fields(inp[18*i+15])[2]) if xAdd > 0 { stack = append(stack, pair{first: yAdd, second: i}) } else { var s pair var toAdd int s, stack = stack[len(stack)-1], stack[:len(stack)-1] if part == 1 { toAdd = 9 for toAdd+s.first+xAdd > 9 { toAdd-- } } else if part == 2 { toAdd = 1 for toAdd+s.first+xAdd < 1 { toAdd++ } } model[s.second] = toAdd model[i] = toAdd + s.first + xAdd } } fmt.Println("# Part", part) for i := range model { fmt.Print(model[i]) } fmt.Println() }