From 1e4b9ba2d744b4c5a198f7b68ceddb5a3daa9c97 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Sun, 15 Dec 2024 09:12:24 -0600 Subject: [PATCH] 2024 Day 15 Complete! --- 2024/day15/input | 71 +++++++++++++ 2024/day15/main.go | 229 ++++++++++++++++++++++++++++++++++++++++++ 2024/day15/testinput | 21 ++++ 2024/day15/testinput2 | 10 ++ 2024/day15/testinput3 | 9 ++ 5 files changed, 340 insertions(+) create mode 100644 2024/day15/input create mode 100644 2024/day15/main.go create mode 100644 2024/day15/testinput create mode 100644 2024/day15/testinput2 create mode 100644 2024/day15/testinput3 diff --git a/2024/day15/input b/2024/day15/input new file mode 100644 index 0000000..8136c3c --- /dev/null +++ b/2024/day15/input @@ -0,0 +1,71 @@ +################################################## +#...O.#O#O..OO.O.#..O....O...#.O....OOO.O.O...#..# +#O.O.OO.##O.....O....#....#.O#O...O.....O...O..#.# +#.O..OOO..OO.O..O..##O..O....OO..O..OO..#..O.....# +#...O...OO............#...OO....O.#O...O....OO..## +#....#O.O....O.OO....OO..#OOO.OO...O.O.........O.# +#.......O.#O...O.#.O#O..OOO.O..#.O.#........#..O.# +#..O.....O...O....#......O.##OOO#...O.#.........O# +#.#OO.O...#OOO#...O...#O.....OOO..O.........##..O# +#O.O.OO.#O....OO.OO.............#..O.OO.....O..O.# +#..OO...OOO..#....OO.OOO..O.......O.#..#..#....O.# +#.O.......O.....O.O.O.O.................#OOOOO.#.# +#.#O....#.O#O....O#....OO...OO.O.....O.....#.O##.# +#.#O.#..O.OOO.......O.OO#...O.O.O.#O.....O..O#...# +#..O#...O.O....O.............OOOO....OO.O..#.....# +#.O#.OO#O.O..O#OOO...#......#.......O...OOO#.OO..# +#...OO.O.O.O#..OO#....O#.OOO.OO#O......#.#.O.OO..# +#...O....O#O..O..O.#..OO....O.O.O......#..OO.#.O.# +#O.O#OO.OO.O.#...............O....O........OO....# +#.....O......O...O.O.O.OOO...O..OO.OOO.OO.OO..#..# +#.##...O....O.......OO..#OOO.....O....O#.........# +#.OO..O.O...#O..OOO..O..O..O......O........#..OOO# +#OOO...OOOO#...OO....OO.....O#...O....O.OO..OO...# +#..O...O...#.O.##OO.......OOO#...OO....O..O..O...# +#..O.#O.#O...#.OO.......@O.....O....#...O....O.O.# +#...OO.OOO...O.O..O.....O.O...O.O.OOO.#.OOO.O#...# +#.....OO.O...O.O#O...........O....OO#...#..O.#OO.# +#.O....O..O..O..#OO#.........OO.#..#....O...OO.OO# +#...O#.OO.O....OO............O.O.O..#.......O...O# +#.....O#.....O.....O...O.O..OOO..OOO...#.....OOO.# +#..O....#.O...O......O..OOO.O...O.O..O..OOOOOO#..# +#O#.O.O..#.....O...O..O...O..OOO.O..OO....O.O..O.# +#.#.O..O.O.....#...O.O...OO.OO..#O.O......O..O.OO# +##..O.O...............#.....OO...O...#O.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...O.......#.#OO....O.O#.# +#.#O...O..O....O...O.............#..O.#.#.#......# +#.#...O..#.#...#OO.....O..OO......O...OO.........# +#....OOOO...O.....O.OOO......O.##..O...O.O.O.O.O.# +#....O.O..#...O.O.....#OO.OO.....#...O#O#......O.# +#...#.O......O..O..#...O##OO.#...#.O.........O..O# +#O.OO..O....OOO...O.O.OO.#........O.OO#O..#.O.#.O# +##..#.....O.#O....O#.........O.O....O..O..O..O.#.# +#..OO...O.....O.O.....O..OO..O.OO..OO.OO.O...OO..# +#..............O#OO......##..#OO#...#.O#.OO..O...# +#OO..O....O#.O..O..O......OOO.....#.O.......OO...# +#.O.#O.#.#.O.........O#..O........O.O.#.OO.......# +#........OOOO....OO..O#.O..O.##OO..O...OOOO.OO...# +################################################## + +^<<<^^^vv>^^<^^^v<<^^<<>^>>vv^>^vv<>>v<>^^v^>v^<<>><<>>v>>^^vvv>vvvvv>>>^>vvvv<<>v^>vv<<<>^^^^^v>>>>>>v<><^<>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main.go new file mode 100644 index 0000000..d7f009a --- /dev/null +++ b/2024/day15/main.go @@ -0,0 +1,229 @@ +package main + +import ( + "fmt" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + fmt.Println() + part2(inp) +} + +func part1(inp []string) { + fmt.Println("# Part 1") + m, dirs := parseInput(inp) + for i := range dirs { + bot, _ := m.FindFirst('@') + move(m, bot, dirs[i]) + } + crates := m.FindAll('O') + var total int + for i := range crates { + add := (crates[i].Y*100 + crates[i].X) + total = total + add + } + fmt.Println("GPS Sum:", total) +} + +func part2(inp []string) { + fmt.Println("# Part 2") + m, dirs := parseInput2(inp) + for i := range dirs { + bot, _ := m.FindFirst('@') + move(m, bot, dirs[i]) + } + crates := m.FindAll('[') + var total int + for i := range crates { + add := (crates[i].Y*100 + crates[i].X) + total = total + add + } + fmt.Println("GPS Sum:", total) +} + +func move(m h.CoordByteMap, orig h.Coordinate, dir byte) bool { + if !canMove(m, orig, dir) { + return false + } + oB := m.Get(orig) + if dir == '^' || dir == 'v' { + switch oB { + case ']': + return moveCrate(m, orig.West(), dir) + case '[': + return moveCrate(m, orig, dir) + } + } + var moveTo h.Coordinate + switch dir { + case '^': + moveTo = orig.North() + case '>': + moveTo = orig.East() + case 'v': + moveTo = orig.South() + case '<': + moveTo = orig.West() + } + dest := m.Get(moveTo) + if dest == '#' { + // A wall, can't move + return false + } else if dest != '.' { + // Not a wall, but not empty, can we push it? + if !move(m, moveTo, dir) { + return false + } + // Fall through + } + m.Put(moveTo, oB) + m.Put(orig, '.') + return true +} + +func moveCrate(m h.CoordByteMap, orig h.Coordinate, dir byte) bool { + if !canMoveCrate(m, orig, dir) { + return false + } + var moveTo h.Coordinate + switch dir { + case '^': + moveTo = orig.North() + case 'v': + moveTo = orig.South() + } + destW, destE := m.Get(moveTo), m.Get(moveTo.East()) + if destW == '#' || destE == '#' { + // A wall, can't move + return false + } else { + if destW != '.' && !move(m, moveTo, dir) { + return false + } + // Check other half of crate + if (destE != '.' && destE != ']') && !move(m, moveTo.East(), dir) { + return false + } + // Fall through + } + m.Put(moveTo, '[') + m.Put(moveTo.East(), ']') + m.Put(orig, '.') + m.Put(orig.East(), '.') + return true +} + +func canMove(m h.CoordByteMap, orig h.Coordinate, dir byte) bool { + oB := m.Get(orig) + if dir == '^' || dir == 'v' { + switch oB { + case ']': + return canMoveCrate(m, orig.West(), dir) + case '[': + return canMoveCrate(m, orig, dir) + } + } + var moveTo h.Coordinate + switch dir { + case '^': + moveTo = orig.North() + case '>': + moveTo = orig.East() + case 'v': + moveTo = orig.South() + case '<': + moveTo = orig.West() + } + dest := m.Get(moveTo) + if dest == '#' { + // A wall, can't move + return false + } else if dest != '.' { + // Not a wall, but not empty, can we push it? + if !canMove(m, moveTo, dir) { + return false + } + // Fall through + } + // can move + return true +} + +func canMoveCrate(m h.CoordByteMap, orig h.Coordinate, dir byte) bool { + var moveTo h.Coordinate + switch dir { + case '^': + moveTo = orig.North() + case 'v': + moveTo = orig.South() + } + destW, destE := m.Get(moveTo), m.Get(moveTo.East()) + + if destW == '#' || destE == '#' { + // A wall, can't move + return false + } else { + if destW != '.' && !canMove(m, moveTo, dir) { + return false + } + // Check other half of crate + if destE != '.' && !canMove(m, moveTo.East(), dir) { + return false + } + // Fall through + } + // can move + return true +} + +func parseInput(inp []string) (h.CoordByteMap, []byte) { + var m h.CoordByteMap + var dirs []byte + var inDirs bool + for i := range inp { + if inDirs { + dirs = append(dirs, []byte(inp[i])...) + } else { + if inp[i] == "" { + m = h.StringSliceToCoordByteMap(inp[:i]) + inDirs = true + } + } + } + return m, dirs +} + +func parseInput2(inp []string) (h.CoordByteMap, []byte) { + // First modify the input + var m h.CoordByteMap + var newMap []string + var inDirs bool + var dirs []byte + for i := range inp { + if inDirs { + dirs = append(dirs, []byte(inp[i])...) + } else { + if inp[i] == "" { + m = h.StringSliceToCoordByteMap(newMap) + inDirs = true + } + var newLine []byte + for j := range inp[i] { + switch inp[i][j] { + case 'O': + newLine = append(newLine, []byte{'[', ']'}...) + case '@': + newLine = append(newLine, []byte{'@', '.'}...) + default: + newLine = append(newLine, []byte{inp[i][j], inp[i][j]}...) + } + } + newMap = append(newMap, string(newLine)) + } + } + return m, dirs +} diff --git a/2024/day15/testinput b/2024/day15/testinput new file mode 100644 index 0000000..84cf1fb --- /dev/null +++ b/2024/day15/testinput @@ -0,0 +1,21 @@ +########## +#..O..O.O# +#......O.# +#.OO..O.O# +#..O@..O.# +#O#..O...# +#O..O..O.# +#.OO.O.OO# +#....O...# +########## + +^v>^vv^v>v<>v^v<<><>>v^v^>^<<<><^ +vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<^<^^>>>^<>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^v^^<^^vv< +<>^^^^>>>v^<>vvv^>^^^vv^^>v<^^^^v<>^>vvvv><>>v^<<^^^^^ +^><^><>>><>^^<<^^v>>><^^>v>>>^v><>^v><<<>vvvv>^<><<>^>< +^>><>^v<><^vvv<^^<><^v<<<><<<^^<^>>^<<<^>>^v^>>^v>vv>^<<^v<>><<><<>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^ +<><^^>^^^<>^vv<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<> +^^>vv<^v^v^<>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<>< +v^^>>><<^^<>>^v^v^<<>^<^v^v><^<<<><<^vv>>v>v^<<^ diff --git a/2024/day15/testinput2 b/2024/day15/testinput2 new file mode 100644 index 0000000..8163605 --- /dev/null +++ b/2024/day15/testinput2 @@ -0,0 +1,10 @@ +######## +#..O.O.# +##@.O..# +#...O..# +#.#.O..# +#...O..# +#......# +######## + +<^^>>>vv>v<< diff --git a/2024/day15/testinput3 b/2024/day15/testinput3 new file mode 100644 index 0000000..6ee6098 --- /dev/null +++ b/2024/day15/testinput3 @@ -0,0 +1,9 @@ +####### +#...#.# +#.....# +#..OO@# +#..O..# +#.....# +####### + +