- Rust 100%
| .github | ||
| .vscode | ||
| benches | ||
| inputs | ||
| src | ||
| .gitignore | ||
| Cargo.toml | ||
| README.md | ||
Advent of Code 2023 
What is Advent of Code? 🎄
Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. Each day there will be a new problem that is split into 2 parts. The second parts is a more difficult variation of the first part. This repository contains my solutions to the Advent of Code 2023 puzzles
Some of the techniques used in the solutions
- Parser combinator to read the puzzle inputs
- Range math to track multiple mappings between values during Day 05
- Quadratic programming during Day 06 to find the minimum and maximum of a function. Which avoids having to use a brute force approach and instead solving it in constant time.
- Cycle detection during Day 08 to count the length of a sub cycle and then use that to calculate the length of the full cycle with the least common multiple.
- Pascal's triangle during Day 09 to calculate the binomial coefficients and predict the next value in a sequence.
- Point in Polygon during Day 10 to determine how many free spaces are enclosed by a line.
- Dynamic Programming during Day 12 to solve the recursiveness of the problem in a reasonable time.
- A* search algorithm during Day 17 to find the shortest path between two points, while following certain restrictions.
- Shoelace formula and Pick's theoremduring Day 18 to calculate the area of a polygon. Here is a rendering of the Day 18 Part 1 and Day 18 Part 2 polygon.
Solutions
| Day | Stars | Code | Execution Time |
|---|---|---|---|
| Day 01: Trebuchet?! | ⭐ ⭐ | Code | 1.003 ms |
| Day 02: Cube Conundrum | ⭐ ⭐ | Code | 0.325 ms |
| Day 03: Gear Ratios | ⭐ ⭐ | Code | 4.476 ms |
| Day 04: Scratchcards | ⭐ ⭐ | Code | 0.867 ms |
| Day 05: If You Give A Seed A Fertilizer | ⭐ ⭐ | Code | 0.360 ms |
| Day 06: Wait For It | ⭐ ⭐ | Code | 0.068 ms |
| Day 07: Camel Cards | ⭐ ⭐ | Code | 2.450 ms |
| Day 08: Haunted Wasteland | ⭐ ⭐ | Code | 3.930 ms |
| Day 09: Mirage Maintenance | ⭐ ⭐ | Code | 0.929 ms |
| Day 10: Pipe Maze | ⭐ ⭐ | Code | 2.291 ms |
| Day 11: Cosmic Expansion | ⭐ ⭐ | Code | 2.566 ms |
| Day 12: Hot Springs | ⭐ ⭐ | Code | 4.443 ms |
| Day 13: Point of Incidence | ⭐ ⭐ | Code | 1.251 ms |
| Day 14: Parabolic Reflector Dish | ⭐ ⭐ | Code | 63.610 ms |
| Day 15: Lens Library | ⭐ ⭐ | Code | 1.274 ms |
| Day 16: The Floor Will Be Lava | ⭐ ⭐ | Code | 19.653 ms |
| Day 17: Clumsy Crucible | ⭐ ⭐ | Code | 197.790 ms |
| Day 18: Lavaduct Lagoon | ⭐ ⭐ | Code | 0.312 ms |
| Day 19: Aplenty | ⭐ ⭐ | Code | 1.084 ms |
Try it out
How to run the code?
To run the code, you'll first need to obtain the puzzle inputs from the Advent of Code website and place them in the input folder. Or save your session cookie in the environment variable AOC_SESSION.
You'll also need to have Rust installed on your system. If you haven't installed it yet, you can download it from here. Once you have Rust installed and the inputs in place, you can run all the puzzles using the following command:
# Run all the days
cargo run --release
# Run a specific days
cargo run --release -- day01
How to benchmark the code?
You can benchmark the performance of the code using the following commands:
# Benchmark all the days
cargo bench
# Benchmark a specific days
cargo bench -- day01