From 6593658d36b60b18789e81ef9a1f5df2dac7e218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Mon, 16 Dec 2024 17:23:18 +0100 Subject: [PATCH] Day 15. part 1. --- data.go | 3 + day_15/data.txt | 71 ++++++++++++++++ day_15/example_data.txt | 10 +++ day_15/example_data_01.txt | 21 +++++ day_15/solution.go | 162 +++++++++++++++++++++++++++++++++++++ day_15/solution_test.go | 26 ++++++ solutions.go | 7 +- 7 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 day_15/data.txt create mode 100644 day_15/example_data.txt create mode 100644 day_15/example_data_01.txt create mode 100644 day_15/solution.go create mode 100644 day_15/solution_test.go diff --git a/data.go b/data.go index d759129..55e1e8e 100644 --- a/data.go +++ b/data.go @@ -45,3 +45,6 @@ var Day13Data string //go:embed day_14/data.txt var Day14Data string + +//go:embed day_15/data.txt +var Day15Data string diff --git a/day_15/data.txt b/day_15/data.txt new file mode 100644 index 0000000..4c39423 --- /dev/null +++ b/day_15/data.txt @@ -0,0 +1,71 @@ +################################################## +#...O.O..O..O...O..........O.O.O.O.....O..O.#.O#.# +#...O.OO.O.......O#.......O.OO....O.#..#...OOO#..# +#O..O....O.O.O.O..O.OOO...O.OO......O....#O.....## +#OO.#O.........OOO....OO....O.O.O..#......OO.O...# +#OO........OOO#O..#O..OOO...O.O.O..OO.#OOOO...#.## +#....#.O.......O.#....OOOO.O..O..O.O##...O....#O## +#.....OOO....O..........O...OO......OO.OO#O...OO.# +#OO.O....O...OO.O.##....OOO.O...O...............## +#O.....O.....#.....#..O..#O.O.O..OO#O..O.OOO...O.# +#.O....O....O..O.O...#.O..O....O.O..O..O.....O...# +#.O.O.....OO.OOOO.O...#O..........O...#.#OO....O.# +#O..O.O.O..O.O....OOO..O#..O.O.O......#O..O.O.#O## +#..O#...O.OO.....#O..O..O....OOOO.O...#OOO..#.#.O# +#.O.....O#.............#.#..OO...OOO....O....OO### +#.#OO....OO..O#....OO..O#...OO..........O...OO...# +#.O.O.....OO.....O.OO.O#...O..O..O...O....O......# +#.O..O....O..O.....#O.O..O.....O..#O...OOOO.O...O# +#O...O....O.OOOO...OO.........O#..#.....#O.O#O#.O# +##...OO...O.....O..O#O...O.........O.#...#..#....# +#OOOO.OO.#...OO.#..O..#O...........OOOO.OO.O....O# +#....O..O.O.OO..O#......#.....OO..OO...O........## +#.O.#....#..........#..OO....OO....##........O.OO# +#..O.O..#.....O##O.O....OO......#O....O....#.....# +#....OO.OO#..OO..O.#....@#O.OOO.O..OO#...#O.OO...# +#..O.....O.........O.O........O#O......O.......O.# +#O.............O....#O.......O..#..#O.O.O...#....# +##...O...OOO..OO..OO.........OOOOO..O.O.O.OO..O.O# +#.#.OOO......#.O..OO.#...O#.O....O..#...#.O......# +#O.O..........O..O...O..OO....O#.O....O.OOO....#.# +#.O.#..OO.OO#..........#.O...O.OO.....O......O.O.# +#.......OO.O.#O..OO.OOO.O........O.............OO# +#O..OOO.#.OO.O.O.....O...O.O..OO.O...O#O##O..O...# +#O.#.O.#O....O..O......O.##O.OOO..O.OOO.O...#....# +#.#........O.OO...#.O...O.....O.##...#.O.OO.O..#O# +#..OO..O....#..O.O#O..O...#O...O#.O.O.O.O...O.#..# +#O.......O#.#O..O#..O..O...#.#.O...........OO....# +#O....................OO.O...O......#..#.OO......# +#OO#..O#....O.OOO.....OOO..#.O..#OO.#....#O.O.O..# +#.O..O.......O.O....#.O...OO....O.OOO...#........# +#.......O...#.....###...O.OO.....O...##..O.#...O.# +#.O.#O...O...O.O#.#..#.#O..O.OO...O#...OOOO.O...O# +##..OO..........O...O.#...OO#O...#O..O..O........# +#...O..O.OO...#O..O#....O....#......OOOO.O...O.O.# +#..O.O...O.O.#O..O.O..#.O.O.......#....O....O.O..# +#O.O.#.OO.....O.........O.##..OO...#.O..O........# +#O..O.OOO..#....O.O#O.O..O......O...O#.OOO.O.O.O.# +#.O....##.##O.O.OO##.O...O....#...#.OO.....O...O.# +#OOO.....#...OOO.O..OOO..O...O......#.O...O..##.O# +################################################## + +^^^<<>v^^^v>>>>v><^v<>v^<><>v>^v^<>v^<^<>^>><^v<^^>v>><<^<^^<<^v^v>^vv>v>>^v<<>>>^>>>^^>>>vv>>^>>><<<^<<<^>^>v>^>v>^><<>><>^>^>^^v<>v<<<^v>v^v>v>v^^v<^v<^>>v^v>^>v^^v<<^^v^v>^<^v^vv>vv><>>><^>><>^^>^>v^<<>^v<^>>v<>^<<^v>>^v><<>^>>v<>^^v<>v^v>>^^^^>v^<<^v>>>>v<><>vvvv<>v><^v>^^vv<<<<>>>v^><>^^^>^^><^><<^^<^^v>>>v^<^^^>vvv^<^>^^^>^>>^v>>^<^vvv<<^v>>><>v^><<>^v<>v<^v<<>^<^vvv>>>^>^v^v^>>^<^^<>>v><<<<^>v>^vv<>>>^>^vvv>>^^<>v<<>^<^v^v>>^^><^<>v^>>vv><<<^v<^>v^^^vv>^v><vv<^v<^<>^^<<^^^v>v>^^^><>v^>>v<<>v^^vv^<<^<>v>>v^^<>^<^>><>>vv>v>^vvv><<<>^v<<^^v><>^<>vvv^>^v>^<<>v>v>v>v<^>>^<>^<<<>^^^v^v><>v>^v><v<>>v^^><<<<^vv<^^>v>vvvv<<^v><^v^v><^><^^v^v^>^>v>>vv^<>>>v^vv>>>vv>>>v<<>^<<<^v^v>><<>^<>>>^<^>vv>>v^><<>v>^<>v<>^v<<>>v>>^v<><<^^>>>v^<<<^><<>v<^^>v<<^v^^^^<<^vv^>>vv<<<^^<^^v^>v>v<^<>^<^v>v^^v^>v^v><<<>vv>v^>^vv^><<^vv^v<<<^>v<>v<><><>v>v^^<^^<>>>vv<>><>>^v^><<^^^<<<<>^<<<><<vv^vv^vv>^v<<^^vv>^v^<>>v<vv>>>>>^v>>^>^><^>v>v<><>^<><^<><<>v^v<><^<<^v^<<<>>^>><>v>^><^>v<^<><^vv<>^<<><>>>>^^v<>v<^v^v><^<^^^^<^<^<>^v>v^<^<<^v><>>^>>vv>>^>v^v<>^v^<vv><^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v^^<><>>v>^vvv>><>v<><^>^v><<>^^>>v^><><>^^v>v>>^>^>^>>^<<^vv<^v>v<^>>^^^^>><>^<<>vv>^^^>v>>v^>>>>v<><>v>vv>>><>v<^<^v>>>>^vv<^^vv<><<>>v>v<<<^v^>v^>^^^>v>v<><<><>^vv>v><v<^v^><<>v>><><>><^v>^^^>>v^v<<<<^>^v>>>>v<<<>>v^>>^>v^<><>>vv<^^v<^v<<^v>v>>v^^^><^^^v>^<^<<>>>v^v>v<>vv^>>v^v^^>>^^<<><>>vv><<>^^^^>^vv>^ +>v><<>^><<<<>^^>v^<><>>^><>v<^vvv^^<><>v^v>vv>^v>^>^><^v>v<^>><^>v>^^vvvvv^v^<>vv<<^v^^><<<><>^>vvv^><v<<>v^>>v><>v<^<<^^^<>v<^^><>v^^>^v>>^>><>v^vv^>^v>v^v>^^>^>^vv><>>>^<^v^v>^^<>v>vvvvv>>>^>^<^v^^><<^>^>^>v>>^v^^v<^>v<>>^^v<^^>><>^><>^><^>^<^<><>^>^<^><^<>^>v>v<<><^^v><<^<^^><^vv>><^vv<<^>>^<^^v>>vvv^^^^^<<><^^^<>^>^v>v<><>v<>^^<<<>>><>>v>^vv>>^<<>^v^^v^>vv^>v^v^v^v<<<^^v<>><<>v^>^>>v><^v><<^^^v^v<>^^^><^>^^v<^v>><>^>^>v^<<^^^vv<>^>^>>>><<<^v>^vv^^><^>><^><^<<<v^<^>^><>v^v^^v>v>v>^v^<><>v<>>>vv^v^><^><<^>^^>v<^^<^v>vvvv<>>v>v^<^^<^><^^^vv>^>vv>^<>>v^<<^>>^>vv^<><v^^^v<>>^>^>v<vv^>^^>>>v<<^>><>v>v>>^>>v^vvv>>v<<>^<^vv<^>^<><<^v<^<^^>>^^^<>><^>v<>^ \ No newline at end of file diff --git a/day_15/example_data.txt b/day_15/example_data.txt new file mode 100644 index 0000000..c6138ff --- /dev/null +++ b/day_15/example_data.txt @@ -0,0 +1,10 @@ +######## +#..O.O.# +##@.O..# +#...O..# +#.#.O..# +#...O..# +#......# +######## + +<^^>>>vv>v<< \ No newline at end of file diff --git a/day_15/example_data_01.txt b/day_15/example_data_01.txt new file mode 100644 index 0000000..b2bce78 --- /dev/null +++ b/day_15/example_data_01.txt @@ -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^<<^ \ No newline at end of file diff --git a/day_15/solution.go b/day_15/solution.go new file mode 100644 index 0000000..0f201e3 --- /dev/null +++ b/day_15/solution.go @@ -0,0 +1,162 @@ +package day_15 + +import ( + "strings" +) + +const ( + Wall = '#' + Player = '@' + Box = 'O' + Empty = '.' +) +const ( + InstUp = '^' + InstDown = 'v' + InstLeft = '<' + InstRight = '>' +) + +type Warehouse [][]rune + +func (w Warehouse) At(x, y int) rune { + if x < 0 || y < 0 || x >= len(w[0]) || y >= len(w) { + return Wall + } + return w[y][x] +} + +// task:https://adventofcode.com/2024/day/13 +func SolveBasic(input string) int { + warehouse, instructions, rX, rY := load(input) + + for _, instr := range instructions { + switch instr { + case InstUp: + rX, rY = moveUp(warehouse, rX, rY) + case InstDown: + rX, rY = moveDown(warehouse, rX, rY) + case InstLeft: + rX, rY = moveLeft(warehouse, rX, rY) + case InstRight: + rX, rY = moveRight(warehouse, rX, rY) + default: + panic("unknown instruction " + string(instr)) + } + } + sum := 0 + for y, line := range warehouse { + for x, val := range line { + if val == Box { + sum += y*100 + x + } + } + } + return sum +} + +// task:https://adventofcode.com/2024/day/12#part2 +func SolveComplex(input string) int { + return 0 +} + +func load(input string) (Warehouse, []rune, int, int) { + substrings := strings.Split(input, "\n\n") + warehouse := Warehouse{} + rX := 0 + rY := 0 + for y, line := range strings.Split(substrings[0], "\n") { + if strings.ContainsRune(line, Player) { + rY = y + rX = strings.IndexRune(line, Player) + } + warehouse = append(warehouse, []rune(line)) + } + instructions := []rune(strings.ReplaceAll(substrings[1], "\n", "")) + + return warehouse, instructions, rX, rY +} + +func moveUp(warehouse Warehouse, x int, y int) (int, int) { + if warehouse.At(x, y-1) == Wall { + return x, y + } else if warehouse.At(x, y-1) == Empty { + warehouse[y][x] = Empty + warehouse[y-1][x] = Player + return x, y - 1 + } else { + newY := y - 1 + for ; warehouse.At(x, newY) == Box; newY-- { + } + if warehouse.At(x, newY) == Empty { + warehouse[newY][x] = Box + warehouse[y-1][x] = Player + warehouse[y][x] = Empty + return x, y - 1 + } + } + return x, y +} + +func moveDown(warehouse Warehouse, x int, y int) (int, int) { + if warehouse.At(x, y+1) == Wall { + return x, y + } else if warehouse.At(x, y+1) == Empty { + warehouse[y][x] = Empty + warehouse[y+1][x] = Player + return x, y + 1 + } else { + newY := y + 1 + for ; warehouse.At(x, newY) == Box; newY++ { + } + if warehouse.At(x, newY) == Empty { + warehouse[newY][x] = Box + warehouse[y+1][x] = Player + warehouse[y][x] = Empty + return x, y + 1 + } + } + return x, y +} + +func moveLeft(warehouse Warehouse, x int, y int) (int, int) { + if warehouse.At(x-1, y) == Wall { + return x, y + } else if warehouse.At(x-1, y) == Empty { + warehouse[y][x] = Empty + warehouse[y][x-1] = Player + return x - 1, y + } else { + newX := x - 1 + for ; warehouse.At(newX, y) == Box; newX-- { + } + if warehouse.At(newX, y) == Empty { + warehouse[y][newX] = Box + warehouse[y][x-1] = Player + warehouse[y][x] = Empty + return x - 1, y + } + } + return x, y +} + +func moveRight(warehouse Warehouse, x int, y int) (int, int) { + if warehouse.At(x+1, y) == Wall { + return x, y + } else if warehouse.At(x+1, y) == Empty { + warehouse[y][x] = Empty + warehouse[y][x+1] = Player + return x + 1, y + } else { + newX := x + 1 + for ; warehouse.At(newX, y) == Box; newX++ { + } + if warehouse.At(newX, y) == Empty { + warehouse[y][newX] = Box + warehouse[y][x+1] = Player + warehouse[y][x] = Empty + return x + 1, y + } + } + return x, y +} diff --git a/day_15/solution_test.go b/day_15/solution_test.go new file mode 100644 index 0000000..a96bc76 --- /dev/null +++ b/day_15/solution_test.go @@ -0,0 +1,26 @@ +package day_15_test + +import ( + "advent_of_code_2024/day_15" + "advent_of_code_2024/helpers" + _ "embed" + "testing" +) + +//go:embed example_data.txt +var ExampleData string + +//go:embed example_data_01.txt +var ExampleData01 string + +func TestBasicSolutionExample(t *testing.T) { + helpers.Check(t, day_15.SolveBasic, helpers.Format(ExampleData), 2028) +} + +func TestBasicSolutionExample01(t *testing.T) { + helpers.Check(t, day_15.SolveBasic, helpers.Format(ExampleData01), 10092) +} + +func TestComplexSolutionExample(t *testing.T) { + helpers.Check(t, day_15.SolveComplex, helpers.Format(ExampleData), 0) +} diff --git a/solutions.go b/solutions.go index 7ef58c5..191ab2e 100644 --- a/solutions.go +++ b/solutions.go @@ -15,6 +15,7 @@ import ( "advent_of_code_2024/day_12" "advent_of_code_2024/day_13" "advent_of_code_2024/day_14" + "advent_of_code_2024/day_15" ) var solutions = map[string]Solution{ @@ -34,8 +35,8 @@ var solutions = map[string]Solution{ "07-complex": {day_07.SolveComplex, Day07Data}, "08-basic": {day_08.SolveBasic, Day08Data}, "08-complex": {day_08.SolveComplex, Day08Data}, - "09-basic": {day_09.SolveBasic, Day08Data}, - "09-complex": {day_09.SolveComplex, Day08Data}, + "09-basic": {day_09.SolveBasic, Day09Data}, + "09-complex": {day_09.SolveComplex, Day09Data}, "10-basic": {day_10.SolveBasic, Day10Data}, "10-complex": {day_10.SolveComplex, Day10Data}, "11-basic": {day_11.SolveBasic, Day11Data}, @@ -47,4 +48,6 @@ var solutions = map[string]Solution{ "13-complex": {day_13.SolveComplex, Day13Data}, "14-basic": {day_14.SolveBasic, Day14Data}, "14-complex": {day_14.SolveComplex, Day14Data}, + "15-basic": {day_15.SolveBasic, Day15Data}, + "15-complex": {day_15.SolveComplex, Day15Data}, }