Aoc2023
No description available
Install / Use
/learn @kcaffrey/Aoc2023README
🎄 Advent of Code 2023
Solutions for Advent of Code in Rust.
I wrote up a summary of my solutions and optimizations used here.
<!--- advent_readme_stars table --->2023 Results
| Day | Part 1 | Part 2 | | :---: | :---: | :---: | | Day 1 | ⭐ | ⭐ | | Day 2 | ⭐ | ⭐ | | Day 3 | ⭐ | ⭐ | | Day 4 | ⭐ | ⭐ | | Day 5 | ⭐ | ⭐ | | Day 6 | ⭐ | ⭐ | | Day 7 | ⭐ | ⭐ | | Day 8 | ⭐ | ⭐ | | Day 9 | ⭐ | ⭐ | | Day 10 | ⭐ | ⭐ | | Day 11 | ⭐ | ⭐ | | Day 12 | ⭐ | ⭐ | | Day 13 | ⭐ | ⭐ | | Day 14 | ⭐ | ⭐ | | Day 15 | ⭐ | ⭐ | | Day 16 | ⭐ | ⭐ | | Day 17 | ⭐ | ⭐ | | Day 18 | ⭐ | ⭐ | | Day 19 | ⭐ | ⭐ | | Day 20 | ⭐ | ⭐ | | Day 21 | ⭐ | ⭐ | | Day 22 | ⭐ | ⭐ | | Day 23 | ⭐ | ⭐ | | Day 24 | ⭐ | ⭐ | | Day 25 | ⭐ | ⭐ |
<!--- advent_readme_stars table ---> <!--- benchmarking table --->Benchmarks
| Day | Part 1 | Part 2 |
| :---: | :---: | :---: |
| Day 1 | 34.8µs | 38.2µs |
| Day 2 | 41.8µs | 41.9µs |
| Day 3 | 83.8µs | 98.8µs |
| Day 4 | 49.3µs | 50.1µs |
| Day 5 | 20.5µs | 24.4µs |
| Day 6 | 187.0ns | 102.0ns |
| Day 7 | 94.8µs | 90.7µs |
| Day 8 | 73.7µs | 161.6µs |
| Day 9 | 58.5µs | 54.7µs |
| Day 10 | 264.8µs | 284.7µs |
| Day 11 | 16.3µs | 15.7µs |
| Day 12 | 137.9µs | 618.3µs |
| Day 13 | 12.3µs | 15.9µs |
| Day 14 | 25.0µs | 4.5ms |
| Day 15 | 20.4µs | 85.9µs |
| Day 16 | 58.3µs | 1.7ms |
| Day 17 | 1.6ms | 3.7ms |
| Day 18 | 2.2µs | 2.4µs |
| Day 19 | 83.9µs | 90.9µs |
| Day 20 | 323.9µs | 1.2ms |
| Day 21 | 64.1µs | 494.7µs |
| Day 22 | 82.6µs | 196.7µs |
| Day 23 | 330.4µs | 13.3ms |
| Day 24 | 123.6µs | 18.3µs |
| Day 25 | 256.4µs | - |
Total: 30.64ms
<!--- benchmarking table ---><details> <summary>Template readme</summary>
Template setup
This template supports all major OS (macOS, Linux, Windows).
📝 Create your repository
- Open the template repository on Github.
- Click Use this template and create your repository.
- Clone your repository to your computer.
- If you are solving a previous year's advent of code, change the
AOC_YEARvariable in.cargo/config.tomlto reflect the year you are solving.
💻 Setup rust
- Install the Rust toolchain.
- (recommended) Install the rust-analyzer extension for your code editor.
- (optional) Install a native debugger. If you are using VS Code, CodeLLDB is a good option.
✨ You can start solving puzzles now! Head to the Usage section to see how to use this template. If you like, you can configure some optional features.
Usage
➡️ Scaffold a day
# example: `cargo scaffold 1`
cargo scaffold <day>
# output:
# Created module file "src/bin/01.rs"
# Created empty input file "data/inputs/01.txt"
# Created empty example file "data/examples/01.txt"
# ---
# 🎄 Type `cargo solve 01` to run your solution.
Individual solutions live in the ./src/bin/ directory as separate binaries. Inputs and examples live in the the ./data directory.
Every solution has tests referencing its example file in ./data/examples. Use these tests to develop and debug your solutions against the example input. In VS Code, rust-analyzer will display buttons for running / debugging these unit tests above the unit test blocks.
[!TIP] If a day has multiple example inputs, you can use the
read_file_part()helper in your tests instead ofread_file(). If this e.g. applies to day 1, you can create a second example file01-2.txtand invoke the helper likelet result = part_two(&advent_of_code::template::read_file_part("examples", DAY, 2));. This supports an arbitrary number of example files.
➡️ Download input for a day
[!IMPORTANT] This requires installing the aoc-cli crate.
You can automatically download puzzle input and description by either appending the --download flag to scaffold (e.g. cargo scaffold 4 --download) or with the separate download command:
# example: `cargo download 1`
cargo download <day>
# output:
# [INFO aoc] 🎄 aoc-cli - Advent of Code command-line tool
# [INFO aoc_client] 🎅 Saved puzzle to 'data/puzzles/01.md'
# [INFO aoc_client] 🎅 Saved input to 'data/inputs/01.txt'
# ---
# 🎄 Successfully wrote input to "data/inputs/01.txt".
# 🎄 Successfully wrote puzzle to "data/puzzles/01.md".
➡️ Run solutions for a day
# example: `cargo solve 01`
cargo solve <day>
# output:
# Finished dev [unoptimized + debuginfo] target(s) in 0.13s
# Running `target/debug/01`
# Part 1: 42 (166.0ns)
# Part 2: 42 (41.0ns)
The solve command runs your solution against real puzzle inputs. To run an optimized build of your code, append the --release flag as with any other rust program.
Submitting solutions
[!IMPORTANT] This requires installing the aoc-cli crate.
Append the --submit <part> option to the solve command to submit your solution for checking.
➡️ Run all solutions
cargo all
# output:
# Running `target/release/advent_of_code`
# ----------
# | Day 01 |
# ----------
# Part 1: 42 (19.0ns)
# Part 2: 42 (19.0ns)
# <...other days...>
# Total: 0.20ms
This runs all solutions sequentially and prints output to the command-line. Same as for the solve command, the --release flag runs an optimized build.
➡️ Benchmark your solutions
# example: `cargo time 8 --store`
cargo time <day> [--all] [--store]
# output:
# Day 08
# ------
# Part 1: 1 (39.0ns @ 10000 samples)
# Part 2: 2 (39.0ns @ 10000 samples)
#
# Total (Run): 0.00ms
#
# Stored updated benchmarks.
The cargo time command allows you to benchmark your code and store timings in the readme. When benching, the runner will run your code between 10 and 10.000 times, depending on execution time of first execution, and print the average execution time.
cargo time has three modes of execution:
cargo timewithout arguments incrementally benches solutions that do not have been stored in the readme yet and skips the rest.cargo time <day>benches a single solution.cargo time --allbenches all solutions.
By default, cargo time does not write to the readme. In order to do so, append the --store flag: cargo time --store.
Please note that these are not scientific benchmarks, understand them as a fun approximation. 😉 Timings, especially in the microseconds range, might change a bit between invocations.
➡️ Run all tests
cargo test
To run tests for a specific day, append --bin <day>, e.g. cargo test --bin 01. You can further scope it down to a specific part, e.g. cargo test --bin 01 part_one.
➡️ Read puzzle description
[!IMPORTANT] This command requires installing the aoc-cli crate.
# example: `cargo read 1`
cargo read <day>
# output:
# Loaded session cookie from "/Users/<snip>/.adventofcode.session".
# Fetching puzzle for day 1, 2022...
# ...the input...
➡️ Scaffold, download & read the current aoc day
[!IMPORTANT] This command requires installing the aoc-cli crate.
During december, the today shorthand command can be used to:
- scaffold a solution for the current day
- download its input
- and read the puzzle
in one go.
# example: `cargo today` on December 1st
cargo today
# output:
# Created module file "src/bin/01.rs"
# Created empty input file "data/inputs/01.txt"
# Created empty example file "data/examples/01.txt"
# ---
# 🎄 Type `cargo solve 01` to run your solution.
# [INFO aoc] 🎄 aoc-cli - Advent of Code command-line tool
# [INFO aoc_client] 🎅 Saved puzzle to 'data/puzzles/01.md'
# [INFO aoc_client] 🎅 Saved input to 'data/inputs/01.txt'
# ---
# 🎄 Successfully wrote input to "data/inputs/01.txt".
# 🎄 Successfully wrote puzzle to "data/puzzles/01.md".
#
# Loaded session cookie from "/Users/<snip>/.adventofcode.session".
# Fetching puzzle for day 1, 2022...
# ...t
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
