This commit is contained in:
Brian Buller 2022-12-27 14:59:52 -06:00
parent 48f30b8e42
commit 3159f13450

View File

@ -2,39 +2,22 @@ package main
import ( import (
"fmt" "fmt"
"image"
h "git.bullercodeworks.com/brian/adventofcode/helpers" h "git.bullercodeworks.com/brian/adventofcode/helpers"
) )
const (
dirU = iota
dirR
dirD
dirL
rocks = 5
debug = false
)
var (
emptyRow = []byte{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'}
bottomRow = []byte{'+', '-', '-', '-', '-', '-', '-', '-', '+'}
)
func main() { func main() {
inp := h.StdinToString() inp := h.StdinToString()
rocks := [][]image.Point{ rocks := [][]h.Coordinate{
{{0, 0}, {1, 0}, {2, 0}, {3, 0}}, {{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}, {X: 3, Y: 0}},
{{1, 2}, {0, 1}, {1, 1}, {2, 1}, {1, 0}}, {{X: 1, Y: 2}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 2, Y: 1}, {X: 1, Y: 0}},
{{2, 2}, {2, 1}, {0, 0}, {1, 0}, {2, 0}}, {{X: 2, Y: 2}, {X: 2, Y: 1}, {X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}},
{{0, 3}, {0, 2}, {0, 1}, {0, 0}}, {{X: 0, Y: 3}, {X: 0, Y: 2}, {X: 0, Y: 1}, {X: 0, Y: 0}},
{{0, 1}, {1, 1}, {0, 0}, {1, 0}}, {{X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}, {X: 1, Y: 0}},
} }
grid := map[image.Point]struct{}{} grid := map[h.Coordinate]struct{}{}
move := func(rock []image.Point, delta image.Point) bool { move := func(rock []h.Coordinate, delta h.Coordinate) bool {
nrock := make([]image.Point, len(rock)) nrock := make([]h.Coordinate, len(rock))
for i, p := range rock { for i, p := range rock {
p = p.Add(delta) p = p.Add(delta)
if _, ok := grid[p]; ok || p.X < 0 || p.X >= 7 || p.Y < 0 { if _, ok := grid[p]; ok || p.X < 0 || p.X >= 7 || p.Y < 0 {
@ -64,15 +47,15 @@ func main() {
} }
cache[k] = []int{i, height} cache[k] = []int{i, height}
rock := []image.Point{} rock := []h.Coordinate{}
for _, p := range rocks[i%len(rocks)] { for _, p := range rocks[i%len(rocks)] {
rock = append(rock, p.Add(image.Point{2, height + 3})) rock = append(rock, p.Add(h.Coordinate{X: 2, Y: height + 3}))
} }
for { for {
move(rock, image.Point{int(inp[jet]) - int('='), 0}) move(rock, h.Coordinate{X: int(inp[jet]) - int('='), Y: 0})
jet = (jet + 1) % len(inp) jet = (jet + 1) % len(inp)
if !move(rock, image.Point{0, -1}) { if !move(rock, h.Coordinate{X: 0, Y: -1}) {
for _, p := range rock { for _, p := range rock {
grid[p] = struct{}{} grid[p] = struct{}{}
if p.Y+1 > height { if p.Y+1 > height {