Advent of Code - Day 20: Race Condition

2024-12-20-generated.png

The Historians are quite pixelated again. This time, a massive, black building looms over you - you’re right outside the CPU!

While The Historians get to work, a nearby program sees that you’re idle and challenges you to a race. Apparently, you’ve arrived just in time for the frequently-held race condition festival!

-- Day 20 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Part 1

To represent each point in the grid of the assignment I created the GridPlace class. Which contains the value of the character in the grid as well as the distance from the start (as computed by the path taken).

[Read More]

Advent of Code - Day 19: Linen Layout

2024-12-19-generated.png

Today, The Historians take you up to the hot springs on Gear Island! Very suspiciously, absolutely nothing goes wrong as they begin their careful search of the vast field of helixes.

-- Day 19 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Part 1

The solution for part 1 today can be resolved by creating a regular expression of all allowed rugs (line 16) and then checking each line in the input to see if it matches.

[Read More]

Advent of Code - Day 18: RAM Run

2024-12-18-generated.png

You and The Historians look a lot more pixelated than you remember. You’re inside a computer at the North Pole!

-- Day 18 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Today the assignment involves yet another grid and pathfinding algorithm. So to read the input into memory I created this small method.

1public void readInput() {  
2    grid = new CharGrid(71, 71);
3    inputLoader.splitOnNewLine()  
4            .map(Point::of)  
5            .limit(1024)                        // limit of bytes to fall part1  
6            .forEach(point -> grid.set(point, '#'));  
7}

Part 1

Since the best solution is using the Dijkstra pathfinding algorithm I created a HistorianStep implementation of the Node<T> that is required by the algorithm.

[Read More]

Advent of Code - Day 17: Chronospatial Computer

2024-12-17-generated.png

The Historians push the button on their strange device, but this time, you all just feel like you’re falling.

-- Day 17 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Part 1

The first thing for today is modelling Opcode and the ComputeEngine. Where the compute engine represents the machine that is executing the instruction in the input string.

 1enum Opcode {  
 2    adv, bxl, bst, jnz, bxc, out, bdv, cdv  
 3}
 4
 5public static class ComputeEngine {  
 6    private final long[] registers;  
 7  
 8    int[] program;  
 9    int instructionPointer;  
10  
11    List<Integer> output = new ArrayList<>();  
12  
13    public ComputeEngine(long[] registers, int[] program) {  
14        this.registers = registers;  
15        this.program = program;  
16        this.instructionPointer = 0;  
17    }
18}

Using these two entities it is already possible to create the method that converts the input string.

[Read More]

Advent of Code - Day 16: Reindeer Maze

2024-12-16-generated.png

It’s time again for the Reindeer Olympics! This year, the big event is the Reindeer Maze, where the Reindeer compete for the lowest score.

-- Day 16 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Part 1

Since the problem statement clearly indicates that a path solving algorithm would be best suited I decided to re-use the existing Dijkstra implementation. To use it I added the Step class which implements the Node<T> used by the algorithm.

[Read More]

Advent of Code - Day 14: Restroom Redoubt

2024-12-14-generated.png

One of The Historians needs to use the bathroom; fortunately, you know there’s a bathroom near an unvisited location on their list, and so you’re all quickly teleported directly to the lobby of Easter Bunny Headquarters.

-- Day 14 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Since the input is a robot I already added the following code before even starting any of the solution algorithms.

[Read More]

Advent of Code - Day 13: Claw Contraption

2024-12-13-generated.png

Next up: the lobby of a resort on a tropical island. The Historians take a moment to admire the hexagonal floor tiles before spreading out.

Fortunately, it looks like the resort has a new arcade! Maybe you can win some prizes from the claw machines?

-- Day 13 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

First I created some records to represent the various entities in the assignment. This consists out of the PlayCost representing the amount of steps that each hit of the button will cost. The second record WinPoint represents the exact location that has to be hit to win a game.

[Read More]

Advent of Code - Day 12: Garden Groups

2024-12-12-generated.png

You’re about to settle near a complex arrangement of garden plots when some Elves ask if you can lend a hand. They’d like to set up fences around each region of garden plots, but they can’t figure out how much fence they need to order or how much it will cost. They hand you a map (your puzzle input) of the garden plots.

-- Day 12 - Advent of Code 2024

[Read More]

Advent of Code - Day 11: Plutonian Pebbles

2024-12-11-generated.png

The ancient civilization on Pluto was known for its ability to manipulate spacetime, and while The Historians explore their infinite corridors, you’ve noticed a strange set of physics-defying stones.

-- Day 11 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Part 1

For today the first step is writing a recursive method that computes the amount of blinks per stone in the input. This method stonesAfterBlink accepts the amount of blinks remaining, which is 25 for part 1. And uses a map as a cache, to prevent recalculation of any situation with the same amount of blinks left and for the same stone.

[Read More]

Advent of Code - Day 10: Hoof it

2024-12-10-generated.png

You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat.

-- Day 10 - Advent of Code 2024

Solution in Java

Full source can be found: in GitHub

Part 1

The first step of today is to write a path finding algorithm based on Dijkstra. This will look for any path where each step size would be exactly 1 (line 12). And if the number 9 is found then the amount of found paths is increased.

[Read More]