From 3159f13450d345fb61f475d77402487f94036aa0 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Tue, 27 Dec 2022 14:59:52 -0600 Subject: [PATCH] Cleanup --- 2022/day17/main.go | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/2022/day17/main.go b/2022/day17/main.go index ff66437..b731d86 100644 --- a/2022/day17/main.go +++ b/2022/day17/main.go @@ -2,39 +2,22 @@ package main import ( "fmt" - "image" h "git.bullercodeworks.com/brian/adventofcode/helpers" ) -const ( - dirU = iota - dirR - dirD - dirL - - rocks = 5 - - debug = false -) - -var ( - emptyRow = []byte{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'} - bottomRow = []byte{'+', '-', '-', '-', '-', '-', '-', '-', '+'} -) - func main() { inp := h.StdinToString() - rocks := [][]image.Point{ - {{0, 0}, {1, 0}, {2, 0}, {3, 0}}, - {{1, 2}, {0, 1}, {1, 1}, {2, 1}, {1, 0}}, - {{2, 2}, {2, 1}, {0, 0}, {1, 0}, {2, 0}}, - {{0, 3}, {0, 2}, {0, 1}, {0, 0}}, - {{0, 1}, {1, 1}, {0, 0}, {1, 0}}, + rocks := [][]h.Coordinate{ + {{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}, {X: 3, Y: 0}}, + {{X: 1, Y: 2}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 2, Y: 1}, {X: 1, Y: 0}}, + {{X: 2, Y: 2}, {X: 2, Y: 1}, {X: 0, Y: 0}, {X: 1, Y: 0}, {X: 2, Y: 0}}, + {{X: 0, Y: 3}, {X: 0, Y: 2}, {X: 0, Y: 1}, {X: 0, Y: 0}}, + {{X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}, {X: 1, Y: 0}}, } - grid := map[image.Point]struct{}{} - move := func(rock []image.Point, delta image.Point) bool { - nrock := make([]image.Point, len(rock)) + grid := map[h.Coordinate]struct{}{} + move := func(rock []h.Coordinate, delta h.Coordinate) bool { + nrock := make([]h.Coordinate, len(rock)) for i, p := range rock { p = p.Add(delta) 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} - rock := []image.Point{} + rock := []h.Coordinate{} 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 { - 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) - if !move(rock, image.Point{0, -1}) { + if !move(rock, h.Coordinate{X: 0, Y: -1}) { for _, p := range rock { grid[p] = struct{}{} if p.Y+1 > height {