/advent-of-code

Repository for all years of advent of code

Primary LanguageJavaMIT LicenseMIT

Advent of Code Solutions

Welcome to the repository containing my solutions for Advent of Code, an annual coding event that takes place every December. Each day, a new programming challenge is released, and this repository contains my attempts to solve those challenges.

Repository structure

The repository is organized as a Java project with a submodule named solutions and one called annotation-scanner.

Annotation Scanner

The annotation scanner module supports the generation of the DaySolver class for each year. This annotation scanner will add an instance of the DaySolver in the bean context registry.

Automated test generation is done using the generation test classes per year with test cases for each case. A test case is determined by files in the following location:

test/resources/input/%year%/day_%day%_%test-case%

Where the year and day are substituted with the year and day of the challenge, and the test-case is the name of the test case.

Solutions

The solutions module includes a package com.github.gjong.advent with subpackages for each year, prefixed with a 'y', and additional subpackages for shared logic: common, algo, and geo.

advent-of-code/
├── solutions/
│   ├── src/
│   │   └── main/
│   │       └── java/
│   │           └── com/
│   │               └── github/
│   │                   └── gjong/
│   │                       └── advent/
│   │                           ├── years/
│   │                           │   ├── y2021/
│   │                           │   │   ├── Day01.java
│   │                           │   │   ├── Day02.java
│   │                           │   |   └── ...
│   │                           │   └── ...
│   │                           ├── common/
│   │                           │   └── CharGrid.java
│   │                           │   └── InputLoader.java
│   │                           │   └── Validator.java
│   │                           ├── algo/
│   │                           │   └── Algo.java
│   │                           ├── geo/
│   │                           |   └── Bounds.java
│   │                           |   └── Point.java
│   │                           |   └── Vector.java
│   │                           └── AdventOfCode.java
│   └── gradle.build.kts
├── README.md
├── gradle.build.kts

Getting started

To run the solutions, you need to have Java 21 or higher installed on your machine. The project is built using Gradle, so you can run the solutions using the following command:

echo "Running solutions for 2021"
./gradlew run --args="2021"

echo "Running solutions for all years"
./gradlew run

Solution statistics

Each solution is timed using the Instant.now() method, and the results are displayed in the table below. The time is measured in milliseconds and includes the time to read the input, run the solution, and validating the output.

The measurements are taken on an AMD Ryzen 5 3600X CPU with 64GB of RAM.

ℹ️ Click on the name of a solution to go to the related source file.

2021 - solutions

Year Day Name Part 1 Part 2 Assignment
2021 01 Sonar Sweep 14ms 14ms instructions
2021 02 Dive! 6ms 1ms instructions
2021 03 Binary Diagnostic 2ms 8ms instructions
2021 04 Giant Squid 23ms 20ms instructions
2021 05 Hydrothermal Venture 71ms 22ms instructions
2021 06 Lanternfish 1ms 0ms instructions
2021 07 The Treachery of Whales 3ms 8ms instructions
2021 08 ... 18ms 10ms instructions
2021 09 Smoke Basin 1ms 3ms instructions
2021 10 Syntax Scoring 6ms 3ms instructions
2021 11 Dumbo Octopus 2ms 0ms instructions
2021 12 Passage Pathing 24ms 717ms instructions
2021 13 Transparent Origami 16ms 18ms instructions
2022 14 Regolith Reservoir 7ms 94ms instructions
2021 15 Chiton 16ms 297ms instructions
2021 16 Packet Decoder 11ms 5ms instructions
2021 17 Trick Shot 20ms 18ms instructions
2021 18 Snailfish 10ms 128ms instructions
2021 21 Dirac Dice 2ms 9664ms instructions

2022 - solutions

Year Day Name Part 1 Part 2 Assignment
2022 01 Calorie Counting 2ms 2ms instructions
2022 02 Rock Paper Scissors 1ms 2ms instructions
2022 03 Rucksack Reorganization 6ms 4ms instructions
2022 04 Camp Cleanup 13ms 3ms instructions
2022 05 Supply Stacks 6ms 5ms instructions
2022 06 Tuning Trouble 3ms 2ms instructions
2022 07 No Space Left On Device 7ms 7ms instructions
2022 08 Treetop Tree House 4ms 3ms instructions
2022 09 Rope Bridge 7ms 9ms instructions
2022 10 Cathode-Ray Tube 2ms 2ms instructions
2022 11 Monkey in the Middle 9ms 107ms instructions
2022 12 Hill Climbing Algorithm 12ms 170ms instructions
2022 13 Distress Signal 7ms 4ms instructions
2022 14 Regolith Reservoir 8ms 95ms instructions

2023 - solutions

Year Day Name Part 1 Part 2 Assignment
2023 01 Trebuchet?! 3ms 13ms instructions
2023 02 Cube Conundrum 1ms 1ms instructions
2023 03 Gear Ratios 24ms 15ms instructions
2023 04 Scratchcards 6ms 6ms instructions
2023 05 If You Give A Seed A Fertilizer 3ms 3ms instructions
2023 06 Wait For It 0ms 0ms instructions
2023 07 Camel Cards 11ms 9ms instructions
2023 08 Haunted Wasteland 6ms 9ms instructions
2023 09 Mirage Maintenance 6ms 4ms instructions
2023 10 Pipe Maze 54ms 0ms instructions
2023 11 Cosmic Expansion 19ms 5ms instructions
2023 12 Hot Springs 16ms 76ms instructions
2023 13 Point of Incidence 2ms 0ms instructions
2023 14 Parabolic Reflector Dish 26ms 1651ms instructions
2023 15 Lens Library 1ms 5ms instructions
2023 16 The Floor Will Be Lava 11ms 464ms instructions
2023 17 Clumsy Crucible 133ms 255ms instructions