2021-12-27 13:19:19 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-12-27 22:59:19 +00:00
|
|
|
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++
|
|
|
|
}
|
2021-12-27 13:19:19 +00:00
|
|
|
}
|
2021-12-27 22:59:19 +00:00
|
|
|
model[s.second] = toAdd
|
|
|
|
model[i] = toAdd + s.first + xAdd
|
2021-12-27 13:19:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-27 22:59:19 +00:00
|
|
|
fmt.Println("# Part", part)
|
|
|
|
for i := range model {
|
|
|
|
fmt.Print(model[i])
|
2021-12-27 13:19:19 +00:00
|
|
|
}
|
2021-12-27 22:59:19 +00:00
|
|
|
fmt.Println()
|
2021-12-27 13:19:19 +00:00
|
|
|
}
|