From 0c611fdc3be9d67661a2cb89cfa800fbc886dded Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 14 Dec 2023 08:31:55 -0600 Subject: [PATCH] 2023 Day 14 Complete! --- 2023/day14/input | 100 +++++++++++++++++ 2023/day14/main.go | 128 ++++++++++++++++++++++ 2023/day14/problem | 203 +++++++++++++++++++++++++++++++++++ 2023/day14/testinput | 10 ++ helpers/coordinateByteMap.go | 71 ++++++------ 5 files changed, 479 insertions(+), 33 deletions(-) create mode 100644 2023/day14/input create mode 100644 2023/day14/main.go create mode 100644 2023/day14/problem create mode 100644 2023/day14/testinput diff --git a/2023/day14/input b/2023/day14/input new file mode 100644 index 0000000..778d2a4 --- /dev/null +++ b/2023/day14/input @@ -0,0 +1,100 @@ +O.O#..O.#...#..O.O#..O#...O..O.#...O#.OO.O...#....#.O.##..####.OOO....OO......##..........#O.#O.O.#. +..O.#..#O...#..#.....O..O..OO..#.O..O#..#O#...#......O.O.O......#..OO##...O..#.O.O..#...#O....O.OO.. +....O#O#.O#...#..O.O#..#.....O....#.....OOO#OO.#....#...#.O.OOOO..#O.O##....##..O.....##.OOO.#..##.. +OO...OO...#..OOO..#....O.#.......##O....#..O.O#..#.O.#..O.#O.#.#..#....#...O.......O#O.....OOO###... +..#...#...O.O....#..O.....#...OO.##O...#O...#.#.O#O.OO.OO.O...#O#...#.#...#.....O..#..O##.##.OO..#.O +..#.#.O.#OO#...#.#O##O.OO..#......#OO....O........#OO#..O.O.....#.....O.O..O.#O#..O......O....O.##.# +.....O..O......O...#.#.#.....#OOO##O.#O...O...O.O..#...#O##.OO......O......OO..O#..##......#OO#..O.. +...#...O.#O.......#.O....#..#.....#.O.#.....#..O..#.....O#..O#.O.O......O###O#..O...OO..##........## +.......#O..O..O........#...#....O..#...#.....#.....#.#O.#.O...O#.....OO.O........#O#O.O..#.....O#O.. +OOO....OO..#O.O#....O#O....OO...O.O...O..O.#..O#........OO....#...#.....OO..O#....##OO#.O#O........O +#.#......O..O...O###O.OO..##......#........O........O......O..O..O.....O.##.O...O..O..OO.O##O.O..#O. +...O.............#.OO.O#.#.....O.O#..OO#.............O..OO.#.O.#O#.O....#..#........O.#.O.......O#.. +.............OO#.....O.O..O..O...O.O..#..#.#..O....OO#..OO..#.O..O#.....#.#....O.O...#.#O....#...O.# +..O..#O.#.#OOO.....#O..OO.##....O..##.O.....O....O..#.#...O.O..O##...O...O..#..O.#O.##.......O...#.. +...O#.....O#O...O....OOO...#.#....##O.....OOO.##...OO.........#.#.#..O....#O#.OO.O........O......... +.......#........#....OO........O...OO.##...O.#.....#....O..OO.O.#...OO..O...O..O....O.#....#.......# +..#....#...##O..#....O#..O.O....#....#..###.#.O.....###..OO....#...OO.OOO#O...##...O.#O#...O...O.O.. +O#..O#...OO..#.......#....OOO...OO.O...OO...##.O..O##.O......#....#O.O..O#OOO.#.O#O.......OO...OO... +OO.#.#...#..O.#.#.OO..OO.#O.#..O....OOO.#.....O.OO....O.#.#..##.....O.#...O......#OO#..O.O..#.....#. +O.....O..O..........O....O..#..#...........#.#O.......#....O.#..##....#O#...#O.O...O#O..#O#..OO.#.O. +.#.##....O.#...OO##O.#..O..OO........O...O......O#OO..OO.O...#..#.O#O.......O#...O.O#..#OOO.O...OO#. +..O..#OO#O#.O..O..#......#.O..#...O..O..O...##O.O..##.....#O.O.OOO.O..O...O...O..O..O....#......#OO. +...OOOO.#.#.O.OO#......#.#.O..O.#...O..O..#......#....##O.#.O.#O#O....###.#..#.....O#.O........O.... +..OO#.........OOO..........O...O..###...##...O........#....O.O#O....#...............#...O..O.O...#.. +.O......#O.OO.....O..#........O#OO.....O....O.O#.O.O...O....#..O#O....#.....O...O#O.O..#.OO..##.#.#. +....O.O#..#...O#.O.O.#......OO..O#..#..#..##...O.#..###.O#.O..O#....O.#..O.O#..##O#....#O.OO#.#..... +O##..#.....##...O......#..O....#O..#O...O.........O..OO......#.#OO##...#.....#......O.....O#..O..#.. +.##.O#O#O...O..#...........#OO....O.#.O.O.#.#O.#..#...O........O...#...#..OOO..##..O......O##O#..... +...O...O#.....#O..#..#..O.#.##O..........#.O..###.O..O#O....O...O#O....OO.O..#.#.O#O#.....#.#.O.OO#O +...O..#O.#O......O....O...O..O#......OO...#..O.OO.O.#..#..#......OOO..#.....OO....O..#.#O......O.... +.....#...##.....O#..O.....#O.#..OO..#.#..##....#.O.#......#.#O.O..O.O.......O......O#.O#O#...OO...#. +......##.O#....O#.....O......#OO#...O....O#....#....O...#..#.#....OO...##OO..#.....##..O..O.O...O..O +OO##..#...OO.......O...#..#..O.....O..OO.OO.#..#.#O.#O..#O.##..............O...O.#O..#..#.O......##. +..O.#.....O#O......O#O#..O.O.....#...OO.#.O.#....#.###....#.#...........O#O.....OO.#..O...#..OO...#O +#..O..O..O#..O...#O.#...###..O..#.O#.#OO.......OO..........O..OOO...#....OO......O..OO#.OO#...O.O.O. +O.O..O..##..O...O.#O#.O.#.O..#O.OO#.OO..O..#...O.........#OO.......O...OO..####O...O..O...#OOO..O.O. +O..#.O.#.OOO...#O.....O#O.#O#.OO...#OO.#.##.........O..O#O#.#.O#...O..O....O..#O...O#O...O..O.O..... +O.O..O...#.O#.#...O..#.O.#.O##.O..#..#...OO#...##.O.#.##.OOO.#.........O.O....#..O.O.....#......OOO. +O..#O.#....OO#..O.##........O...#.#.....OO.....#O...OO........OO.#OO.....#.......O.#..OO#..O.#O#.... +.OO..O.#..#...O.O.OOO#.O...O.O..OO.#O#..OO..#.....#.#..O....O.#O.##...O..O.....#...##...O.O#O...O..O +#....O.#......OO....#..O#.OOO..O.#...O.........###O.....##..O..O.O.O.O....##.....O...O.O..O.O.....O. +#...OO...O....##O........O.O..OO..#.....#.....OO...O...O.....#..O...#.....#.#...#................... +...O....O..OO.OO.......##...#OOO.....O..OO.O#.#........O..O.O....O.#.O#...#.#.........#......O....#. +O.........#..#..##..OO#....#..OO#O....O.O...O...................O.....O..OO.O.O.O..O.#...#...O.#.#O. +....#.O#.O..#..#..#...#OO.#.......O.#....O...O...#.##...O...O....O#.O.....O#....#.#......#.#..O.O.O. +#O##.#.....#.##O..#...O...###.OO......#......#O....#..#..O........#.O..O.....O#..O...OO#..OO.#.OO.OO +.O#.###O.O.#...####O....#.##O.O##.#..#.#..O........###.#....##O....O.O....OO.O...O.#O...OOO##...#.O. +....O..O....O............O.O......OO.##..#OO..#O...#.O.O..#..#O.O.........##.#..#..OO.....O.......#. +O....##.#O...O.OO..O#..O...#...O.OO.#..O.#......#.O..#.#..........O###...OOO.O..#.......O.O.O......O +.#......##...O.....#.O.....O.#.......O#O...O#.O.......O..#O..O#...O..O..OO#..#.O#...O.#.#.O...#.#.OO +...O.#.O.#......##..O..........OOO.....O.O......O.....O..#.O..#...#.OOO...O..#..#...#......O...#...O +..O..OO...#..#O....OO...#O...O#..O##....O#....#..#.#...#...........###...........#...OO...OO........ +OO....O...#OO..O..O.O.O..#.O.....O.#...O........OO...#......O.#....O..O.#.##.........OO.O#...O.OO... +.#.....O.O#O..O.....#.#...O.O##O.......#..O#.#.#.OO#.O.O.#O#..OO..O.#O..O.OOOO......O....O...#..#... +#......O..#...O..#.O....#..OO...#.........O.O...#..O......O.O.O.#.O.......O..##..O#.#..O..#....OO.#. +.O..##O#O.O.O....#...#..O#.#.#.......O........#..#OO.OO..O..O.#...O..OOOO.....O#....O####.......#... +.#OO#.O.#..........OO..O.......O#....#.OO#...##......####...O...OOO...#....O.#..O.......#..O.O...... +....O..#........#OO.......O.#..O...O..O..#.O....#.O.O.O..OO.O#O.O..O.###..O.#.#.......#.#...O#...O.. +OO....O#O.O.#.#.##O#.#O#....#....O.O.......O.O.OO....O#.....O.O.OO#.##.O.#..##O..O..O#O......O...O#O +.#...#O..##.##.OO....##.....#O...#.O.O..#.....##......OO#OO.#...O...#..O....O#.#.O..O.#.......O.#.#O +O.#OO#OOO..O.#..OO..O......#O...O....##..#..#O...OO#.#.OO........O.#...O..O#OOO.O....##.O.O........# +.###..O.O...O#O..OO.O....#...OO.OO.O..OO..O.O.O.........#.O#...#...#..O..#..O..OO..#.O.....OO#...... +.O#...O#..#.....O......O##..O.O.O..#..#.#.....#...#....#..#...O.O#..O...O..#...O......#.#...O.....O. +.O#..OO#.O.O...#O...O.....#....##..####.....O..O.....O...#O..#.......#OOO#.#....O.......O.#O.#..O#.. +......O.O#....O.......O.O...O..O#..O...#....#O..##OO.#O......OOO.....#.#O.O#.O#.O....O#O#O..###.#... +#.O....#O......OOO......##.O.OO....#O...#OO...OO.##...O.O..#OO..OOO#..#.O.........O#...O........#... +.O....#.......O#.O..##...O##OO......#..O.O#O.O.#...........#OO........O...O....#.............#.#..O. +....#O.#..#.#..........OO...O..........O....O#...#OO.......O...O.#OO..OOO....O.O#..O.O.###..O.O#...O +O...#..OO....O.......#.OO...O........O.OO..#..#..#.#.O..O.#....O.O......OO..OO.O..#..OOO#..OOO...... +.OO#.O.....O..#...O.....O....O#........#....#.....O..#..###...#.O.......OO......O..O.OO..O..#.O#O#.. +O....O...##.#....#O..O.#......................O..O#OOO..##....#.#..O.O.....O#..O.O.O...#.#.OOO...O.. +.......O..OO.O..O#.OO.#.O..#O....#.OOO.........##......#.O#.O..O....O....O.....#O.O...O.#.......O.#O +....O##.#...O.##...O#...OOOO...OO...#.O.#...O.#O.......#.O.....##....O.#O....#......##.O....O.OO#..O +OO...O#O#O#.#OO.#O.O..#.#.#.#.............#.O........#...O..O......O#.#OO.O...#.O..O...O#.O....O#..O +.#..O..#.OO.#O...O#.O.#.#..#.......#.......#O...#..#O#....O...#....OO.....O......O..#.....O..O..#.O# +...OO....O.#....#.O.#..#.#O.#.#O.....O..O##.......O..#O.#.O...OOO#O.#......O....#......#......O##... +...##.O.O.....##....O.....#O..O........#.#.O#O....O#..O...O#OO...O....O..O.O.#.#..#OO...O..#....OO.. +O...#OO.O.OO#..O....##O...#....#...#.O.O..O.........#..##.#O.#.OO..OO...#...O.O#.OO..#.O.OO#.#..##OO +..O.O#..O..#O...O.#.O.#....#....#.#O...O..O#O....#...#..#..##......#.O..........OOO........O.#...... +.....#....#....OO....#....O.#O..O...O#O..#...###....O.....O........##.#.#..#.O.OO.#O.O.O..#...O#O..O +.OO.....O.O.....#....O.O....O......O#O....O#.#..O....O.#............#..O.#.....OO....O...O....O.#.O. +.........O#OO.#O.....O......O...#..#O..O.#...O.O..OO.........#.O#OO.#.OO.........#.OO..O.O#O..O.O#.. +#...O...O....#O.###.....O.OO..O..OO.O#O....#O..#O..OO..O..#........O...#.....#..#...OO..O....#.....O +......O.O.OO#.O.......O#O.OO.#..O....O...#.O#..#....O.#....#..#O...#.OO.O#........#......O....O.O... +..#...##...#.O.O..#...O#.....##.......OO..O.#....O.O#O#..O...O#..OO...##O...O..O.....#.#...O.O...... +OOO.O.O#O......#..OO.O...OO...O............O..O#..##O...###.#......O#..#.O..O.OOO...#..O#......#OO.# +O###.......#.O.O.#.....#.OO..O.O...#..O#O..#O.O.#.O..O.O..O#.#....#..#...O#..###.#..O#.O.........OO. +.......#O#OO#...#.#...#.O...O.....O.O#.....O.O.O##.#...#O.#....OO...O.OO..O....O.O..#..#.....O...#.. +.O..###..OO#O.#.#OO.O#...#..O#...O.....O#.O......O...OO..O..O.....O..##.....OO.....O......O........O +..O..#.O.#..OO.O#..O#..O.....OO#O#....OO.OO#O...O...O.O......OO.#O#....O..#O.#.OO##.#....#O#.#...... +O.#O.O.O.O...OO.....O.#...##..#....O....O..#..#O#..O#.#.OO.#O..........#...O..##..O.##.O.O...#.#O..# +......O#...O.#..O#.O.........#.#....O.O....O.#..O..O##.#..O....#..#O#.OO.........#.O##O.....OO.OO.O. +#....#.#O.O.O............O.O.#.O..O.........O..O........O......O.....OO.OO..OO.#....OO.OO.#....#..## +.......#...O.O.#.O.....#.O#.#..O..O...O.O.#O..#...##.........O..#.OO..O........#.....#.......OO..... +...#....O...O...#O.OO...#....#..O.#.O.#......##.#.#.OO.O.O...#..#..O........O.##..O...O#O...OO.O.... +.......OO...O..O...........O###......#....O.......O..O.....O#...#.O.#.#......O..O.....#.#OO.......O. +.#..#.....#.O..O..O.....##..O.........O#.##O....OO...O...#..O.O.##OO......O.#..O....O..O.#.O.O...O.O +.O....O...O....#.O......#..##O.#..O..O.....O...OO..###....#..#..#..........#.#.#.#.#........O...O.O. +.OOO.#.#O....O.#...OO#.##...#...O.#...OO..###..OO.#.O....O..OO#..O..O....O#.#.O####..O....O..O#O.... +.OO.OO#......#....#..##O#O...OO....#....O......OO..OOO.....##.......O#.#.O.#O......O..#.#O..O.O..#.. diff --git a/2023/day14/main.go b/2023/day14/main.go new file mode 100644 index 0000000..25f232a --- /dev/null +++ b/2023/day14/main.go @@ -0,0 +1,128 @@ +package main + +import ( + "fmt" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + fmt.Println() + part2(inp) +} + +func part1(input []string) { + m := h.StringSliceToCoordByteMap(input) + fmt.Println("# Part 1") + tiltNorth(&m) + fmt.Println(calcLoad(&m)) +} + +func part2(input []string) { + target := 1_000_000_000 + mapCache := make(map[string]int) + m := h.StringSliceToCoordByteMap(input) + var i = 0 + var ignoreCache bool + for ; i <= target; i++ { + tiltNorth(&m) + tiltWest(&m) + tiltSouth(&m) + tiltEast(&m) + if !ignoreCache { + if v, ok := mapCache[m.String()]; ok && i > 200 { + target = i + (target-v)%(i-v) - 1 + ignoreCache = true + } + mapCache[m.String()] = i + } + } + fmt.Println("# Part 2") + fmt.Println(calcLoad(&m)) +} + +func c(x, y int) h.Coordinate { return h.Coordinate{X: x, Y: y} } + +// m.FindAll returns a slice sorted Left->Right, Top->Bottom +func tiltNorth(m *h.CoordByteMap) { + rocks := m.FindAll('O') + for i := range rocks { + if rocks[i].Y == m.TLY { + continue + } + mv := h.Coordinate{X: rocks[i].X, Y: rocks[i].Y} + for m.Get(mv.North()) == '.' { + mv.MoveNorth() + } + if !mv.Equals(rocks[i]) { + m.Put(rocks[i], '.') + m.Put(mv, 'O') + } + } +} +func tiltEast(m *h.CoordByteMap) { + rocks := m.FindAll('O') + for i, j := 0, len(rocks)-1; i < j; i, j = i+1, j-1 { + rocks[i], rocks[j] = rocks[j], rocks[i] + } + for i := range rocks { + if rocks[i].X == m.BRX { + continue + } + mv := h.Coordinate{X: rocks[i].X, Y: rocks[i].Y} + for m.Get(mv.East()) == '.' { + mv.MoveEast() + } + if !mv.Equals(rocks[i]) { + m.Put(rocks[i], '.') + m.Put(mv, 'O') + } + } +} +func tiltSouth(m *h.CoordByteMap) { + rocks := m.FindAll('O') + for i, j := 0, len(rocks)-1; i < j; i, j = i+1, j-1 { + rocks[i], rocks[j] = rocks[j], rocks[i] + } + for i := range rocks { + if rocks[i].Y == m.BRY { + continue + } + mv := h.Coordinate{X: rocks[i].X, Y: rocks[i].Y} + for m.Get(mv.South()) == '.' { + mv.MoveSouth() + } + if !mv.Equals(rocks[i]) { + m.Put(rocks[i], '.') + m.Put(mv, 'O') + } + } +} +func tiltWest(m *h.CoordByteMap) { + rocks := m.FindAll('O') + for i := range rocks { + if rocks[i].X == m.TLX { + continue + } + mv := h.Coordinate{X: rocks[i].X, Y: rocks[i].Y} + for m.Get(mv.West()) == '.' { + mv.MoveWest() + } + if !mv.Equals(rocks[i]) { + m.Put(rocks[i], '.') + m.Put(mv, 'O') + } + } +} + +func calcLoad(m *h.CoordByteMap) int { + var res int + bot := m.BRY + rocks := m.FindAll('O') + for i := range rocks { + res += (bot - rocks[i].Y) + 1 + } + return res +} diff --git a/2023/day14/problem b/2023/day14/problem new file mode 100644 index 0000000..11d119e --- /dev/null +++ b/2023/day14/problem @@ -0,0 +1,203 @@ + [1]Advent of Code + + • [2][About] + • [3][Events] + • [4][Shop] + • [5][Settings] + • [6][Log Out] + + br0xen [7](AoC++) 28* + +    $year=[8]2023; + + • [9][Calendar] + • [10][AoC++] + • [11][Sponsors] + • [12][Leaderboard] + • [13][Stats] + + Our [14]sponsors help make Advent of Code possible: + [15]Jane Street - Will our next great idea come from you? We hire smart, + humble people who love to solve problems, build systems, and test + theories. Our success is driven by our people and we never stop improving. + +--- Day 14: Parabolic Reflector Dish --- + + You reach the place where all of the mirrors were pointing: a massive + [16]parabolic reflector dish attached to the side of another large + mountain. + + The dish is made up of many small mirrors, but while the mirrors + themselves are roughly in the shape of a parabolic reflector dish, each + individual mirror seems to be pointing in slightly the wrong direction. If + the dish is meant to focus light, all it's doing right now is sending it + in a vague direction. + + This system must be what provides the energy for the lava! If you focus + the reflector dish, maybe you can go where it's pointing and use the light + to fix the lava production. + + Upon closer inspection, the individual mirrors each appear to be connected + via an elaborate system of ropes and pulleys to a large metal platform + below the dish. The platform is covered in large rocks of various shapes. + Depending on their position, the weight of the rocks deforms the platform, + and the shape of the platform controls which ropes move and ultimately the + focus of the dish. + + In short: if you move the rocks, you can focus the dish. The platform even + has a control panel on the side that lets you tilt it in one of four + directions! The rounded rocks (O) will roll when the platform is tilted, + while the cube-shaped rocks (#) will stay in place. You note the positions + of all of the empty spaces (.) and rocks (your puzzle input). For example: + + O....#.... + O.OO#....# + .....##... + OO.#O....O + .O.....O#. + O.#..O.#.# + ..O..#O..O + .......O.. + #....###.. + #OO..#.... + + Start by tilting the lever so all of the rocks will slide north as far as + they will go: + + OOOO.#.O.. + OO..#....# + OO..O##..O + O..#.OO... + ........#. + ..#....#.# + ..O..#.O.O + ..O....... + #....###.. + #....#.... + + You notice that the support beams along the north side of the platform are + damaged; to ensure the platform doesn't collapse, you should calculate the + total load on the north support beams. + + The amount of load caused by a single rounded rock (O) is equal to the + number of rows from the rock to the south edge of the platform, including + the row the rock is on. (Cube-shaped rocks (#) don't contribute to load.) + So, the amount of load caused by each rock in each row is as follows: + + OOOO.#.O.. 10 + OO..#....# 9 + OO..O##..O 8 + O..#.OO... 7 + ........#. 6 + ..#....#.# 5 + ..O..#.O.O 4 + ..O....... 3 + #....###.. 2 + #....#.... 1 + + The total load is the sum of the load caused by all of the rounded rocks. + In this example, the total load is 136. + + Tilt the platform so that the rounded rocks all roll north. Afterward, + what is the total load on the north support beams? + + Your puzzle answer was 108813. + +--- Part Two --- + + The parabolic reflector dish deforms, but not in a way that focuses the + beam. To do that, you'll need to move the rocks to the edges of the + platform. Fortunately, a button on the side of the control panel labeled + "spin cycle" attempts to do just that! + + Each cycle tilts the platform four times so that the rounded rocks roll + north, then west, then south, then east. After each tilt, the rounded + rocks roll as far as they can before the platform tilts in the next + direction. After one cycle, the platform will have finished rolling the + rounded rocks in those four directions in that order. + + Here's what happens in the example above after each of the first few + cycles: + + After 1 cycle: + .....#.... + ....#...O# + ...OO##... + .OO#...... + .....OOO#. + .O#...O#.# + ....O#.... + ......OOOO + #...O###.. + #..OO#.... + + After 2 cycles: + .....#.... + ....#...O# + .....##... + ..O#...... + .....OOO#. + .O#...O#.# + ....O#...O + .......OOO + #..OO###.. + #.OOO#...O + + After 3 cycles: + .....#.... + ....#...O# + .....##... + ..O#...... + .....OOO#. + .O#...O#.# + ....O#...O + .......OOO + #...O###.O + #.OOO#...O + + This process should work if you leave it running long enough, but you're + still worried about the north support beams. To make sure they'll survive + for a while, you need to calculate the total load on the north support + beams after 1000000000 cycles. + + In the above example, after 1000000000 cycles, the total load on the north + support beams is 64. + + Run the spin cycle for 1000000000 cycles. Afterward, what is the total + load on the north support beams? + + Your puzzle answer was 104533. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should [17]return to your Advent calendar and try + another puzzle. + + If you still want to see it, you can [18]get your puzzle input. + + You can also [Shareon [19]Twitter [20]Mastodon] this puzzle. + +References + + Visible links + 1. https://adventofcode.com/ + 2. https://adventofcode.com/2023/about + 3. https://adventofcode.com/2023/events + 4. https://teespring.com/stores/advent-of-code + 5. https://adventofcode.com/2023/settings + 6. https://adventofcode.com/2023/auth/logout + 7. Advent of Code Supporter + https://adventofcode.com/2023/support + 8. https://adventofcode.com/2023 + 9. https://adventofcode.com/2023 + 10. https://adventofcode.com/2023/support + 11. https://adventofcode.com/2023/sponsors + 12. https://adventofcode.com/2023/leaderboard + 13. https://adventofcode.com/2023/stats + 14. https://adventofcode.com/2023/sponsors + 15. https://www.janestreet.com/ + 16. https://en.wikipedia.org/wiki/Parabolic_reflector + 17. https://adventofcode.com/2023 + 18. https://adventofcode.com/2023/day/14/input + 19. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Parabolic+Reflector+Dish%22+%2D+Day+14+%2D+Advent+of+Code+2023&url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F14&related=ericwastl&hashtags=AdventOfCode + 20. javascript:void(0); diff --git a/2023/day14/testinput b/2023/day14/testinput new file mode 100644 index 0000000..5a24dce --- /dev/null +++ b/2023/day14/testinput @@ -0,0 +1,10 @@ +O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#.... diff --git a/helpers/coordinateByteMap.go b/helpers/coordinateByteMap.go index 71148aa..3af8844 100644 --- a/helpers/coordinateByteMap.go +++ b/helpers/coordinateByteMap.go @@ -42,6 +42,44 @@ func StringSliceToCoordByteMap(input []string) CoordByteMap { return ret } +func (m *CoordByteMap) GetPos(x, y int) byte { + return m.Get(Coordinate{X: x, Y: y}) +} + +func (m *CoordByteMap) Get(pos Coordinate) byte { + if v, ok := m.Field[pos]; ok { + return v + } + return 0 +} + +func (m *CoordByteMap) Opt(pos Coordinate, def byte) byte { + if v, ok := m.Field[pos]; ok { + return v + } + return def +} + +func (m *CoordByteMap) Put(pos Coordinate, val byte) { + if pos.X < m.TLX { + m.TLX = pos.X + } + if pos.Y < m.TLY { + m.TLY = pos.Y + } + if pos.X > m.BRX { + m.BRX = pos.X + } + if pos.Y > m.BRY { + m.BRY = pos.Y + } + m.Field[pos] = val +} + +func (m *CoordByteMap) Delete(pos Coordinate) { + delete(m.Field, pos) +} + func (m *CoordByteMap) Height() int { return m.BRY - m.TLY } @@ -223,39 +261,6 @@ func (m *CoordByteMap) Count(b byte) int { return ret } -func (m *CoordByteMap) Get(pos Coordinate) byte { - if v, ok := m.Field[pos]; ok { - return v - } - return 0 -} - -func (m *CoordByteMap) Opt(pos Coordinate, def byte) byte { - if v, ok := m.Field[pos]; ok { - return v - } - return def -} - -func (m *CoordByteMap) Put(pos Coordinate, val byte) { - if pos.X < m.TLX { - m.TLX = pos.X - } - if pos.Y < m.TLY { - m.TLY = pos.Y - } - if pos.X > m.BRX { - m.BRX = pos.X - } - if pos.Y > m.BRY { - m.BRY = pos.Y - } - m.Field[pos] = val -} -func (m *CoordByteMap) Delete(pos Coordinate) { - delete(m.Field, pos) -} - func (m *CoordByteMap) GrowNorth(size int, val byte) { tlY := m.TLY - 1 for x := m.TLX; x <= m.BRX; x++ {