{"id":30830476,"url":"https://github.com/noook/aoc-rust-2024","last_synced_at":"2025-09-06T15:54:36.126Z","repository":{"id":312857700,"uuid":"1044826030","full_name":"noook/aoc-rust-2024","owner":"noook","description":"Repository where I learn Rust and try to improve algorithms efficiency","archived":false,"fork":false,"pushed_at":"2025-09-02T11:24:25.000Z","size":296,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-02T13:25:32.453Z","etag":null,"topics":["advent-of-code","aoc","aoc-rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-26T09:10:21.000Z","updated_at":"2025-09-02T11:24:28.000Z","dependencies_parsed_at":"2025-09-02T13:25:39.274Z","dependency_job_id":"34430cf4-71c6-4f8c-8f55-b8db4162978a","html_url":"https://github.com/noook/aoc-rust-2024","commit_stats":null,"previous_names":["noook/aoc-rust-2024"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/noook/aoc-rust-2024","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noook%2Faoc-rust-2024","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noook%2Faoc-rust-2024/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noook%2Faoc-rust-2024/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noook%2Faoc-rust-2024/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noook","download_url":"https://codeload.github.com/noook/aoc-rust-2024/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noook%2Faoc-rust-2024/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273926548,"owners_count":25192318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advent-of-code","aoc","aoc-rust"],"created_at":"2025-09-06T15:54:20.780Z","updated_at":"2025-09-06T15:54:36.105Z","avatar_url":"https://github.com/noook.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./.assets/christmas_ferris.png\" width=\"164\"\u003e\n\n# 🎄 Advent of Code 2024 - Rust Learning Journey\n\n\u003e **A portfolio project showcasing systematic learning of Rust, algorithm optimization, and AI-assisted development**\n\nThis repository documents my approach to mastering Rust through [Advent of Code](https://adventofcode.com/) challenges, emphasizing performance optimization, memory efficiency, and modern development practices with AI assistance.\n\n\u003c!--- advent_readme_stars table ---\u003e\n\n## 🎯 Learning Objectives\n\n- **Rust Mastery**: Deep dive into Rust's ownership model, type system, and zero-cost abstractions\n- **Algorithm Optimization**: Focus on computational efficiency and performance benchmarking\n- **Memory Management**: Explore heap allocation patterns and memory optimization techniques\n- **AI-Enhanced Learning**: Use AI as a learning partner for code review, refactoring guidance, and optimization insights after independent problem solving\n\n## 🚀 Performance Benchmarks\n\nAll solutions are optimized for performance with comprehensive benchmarking. Execution times measured on optimized builds:\n\n\u003c!--- benchmarking table ---\u003e\n## Benchmarks\n\n| Day | Part 1 | Part 2 |\n| :---: | :---: | :---:  |\n| [Day 1](./src/bin/01.rs) | `4.1µs` | `40.9µs` |\n| [Day 2](./src/bin/02.rs) | `407.6µs` | `492.8µs` |\n| [Day 3](./src/bin/03.rs) | `258.7µs` | `243.7µs` |\n| [Day 4](./src/bin/04.rs) | `72.4µs` | `48.6µs` |\n| [Day 5](./src/bin/05.rs) | `232.7µs` | `347.8µs` |\n| [Day 6](./src/bin/06.rs) | `49.1µs` | `50.5ms` |\n| [Day 7](./src/bin/07.rs) | `1.1ms` | `24.0ms` |\n| [Day 8](./src/bin/08.rs) | `15.5µs` | `33.9µs` |\n| [Day 9](./src/bin/09.rs) | `259.0µs` | `4.6ms` |\n| [Day 10](./src/bin/10.rs) | `304.7µs` | `29.6µs` |\n| [Day 11](./src/bin/11.rs) | `104.6µs` | `6.9ms` |\n| [Day 12](./src/bin/12.rs) | `4.5ms` | `8.2ms` |\n\n**Total: 102.75ms**\n\u003c!--- benchmarking table ---\u003e\n\n## 🧠 Development Approach\n\n### Independent Problem Solving First\n- **Self-Reliant Analysis**: Initially solve each problem independently, focusing on understanding constraints and developing algorithmic solutions\n- **Original Implementation**: Write first-pass solutions using my own reasoning and Rust knowledge\n- **Personal Learning**: Build problem-solving intuition and strengthen core programming skills through independent work\n\n### AI-Enhanced Learning \u0026 Optimization\n- **Code Review \u0026 Learning**: Use AI to analyze my solutions and learn about alternative approaches or Rust idioms I might have missed\n- **Refactoring Guidance**: Leverage AI for suggesting optimizations while maintaining code readability and safety\n- **Performance Analysis**: Apply AI to interpret DHAT profiling results and understand memory allocation patterns\n- **Knowledge Expansion**: Use AI as a learning partner to deepen understanding of algorithms and Rust-specific optimizations\n\n### Performance-First Methodology\n1. **Benchmark-Driven Development**: Every solution includes comprehensive performance measurements\n2. **Memory Profiling**: Regular heap allocation analysis using DHAT integration\n3. **Algorithmic Optimization**: Focus on optimal time/space complexity for each problem\n4. **Iterative Refinement**: Multiple optimization passes guided by profiling data\n\n### Rust Learning Focus Areas\n- **Zero-Cost Abstractions**: Leveraging Rust's performance guarantees\n- **Memory Safety**: Exploring ownership, borrowing, and lifetime management\n- **Type System**: Utilizing advanced type features for compile-time guarantees\n\n### Iterative Development Process\n- **Version History Documentation**: Most solution's evolution is preserved in git history, showing the journey from initial implementation to optimized final version\n- **Learning Trail**: Commit history demonstrates iterative improvements, refactoring decisions, and optimization discoveries\n- **Transparent Development**: Full development process visible through file history - from first working solution through performance optimizations and code quality improvements\n\n## 🛠️ Technical Implementation\n\n### Code Architecture\n- **Modular Design**: Each day's solution is a standalone binary with dedicated input/example files\n- **Test-Driven Development**: Comprehensive unit tests against example inputs for all solutions\n- **Performance Monitoring**: Integrated benchmarking with automatic README updates\n- **Memory Profiling**: DHAT integration for heap allocation analysis\n\n### Rust-Specific Techniques\n- **Iterator Chains**: Extensive use of functional programming patterns for clean, efficient code\n- **Pattern Matching**: Leveraging Rust's powerful pattern matching for elegant problem decomposition\n- **Type Safety**: Using strong typing to prevent runtime errors and encode invariants\n- **Zero-Copy Operations**: Minimizing allocations through strategic use of slices and references\n\n### Development Tools \u0026 Workflow\n- **Cargo Integration**: Custom commands for scaffolding, testing, and benchmarking\n- **CI/CD**: Automated testing, linting, and performance tracking\n- **Profiling**: Integration with DHAT for detailed memory analysis\n- **Version Control**: Systematic commit patterns documenting optimization journey with full development history preserved for learning reference\n\n---\n\n## 📚 Getting Started\n\n### Quick Start\n```bash\n# Clone and setup\ngit clone \u003crepository-url\u003e\ncd advent-of-code-rust\n\n# Run a specific day's solution\ncargo solve 01\n\n# Benchmark performance\ncargo time 01 --store\n\n# Run all tests\ncargo test\n\n# View development history for any solution\ngit log --oneline src/bin/01.rs\n```\n\n### Development Environment Setup\n\n**Prerequisites:**\n1. Install the [Rust toolchain](https://www.rust-lang.org/tools/install)\n2. (Recommended) Install [rust-analyzer](https://rust-analyzer.github.io/manual.html) for your editor\n3. (Optional) Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) for debugging\n\nThis project supports all major platforms (macOS, Linux, Windows) and includes comprehensive tooling for performance analysis and development workflow optimization.\n\n---\n\n## 🌟 Portfolio Highlights\n\n### Key Achievements\n- **Performance Optimization**: Solutions consistently achieve microsecond-level execution times\n- **Memory Efficiency**: Zero-allocation solutions where possible, with detailed profiling of necessary allocations\n- **Code Quality**: Comprehensive test coverage, documentation, and adherence to Rust best practices\n- **AI-Enhanced Learning**: Strategic use of AI for post-solution analysis, refactoring guidance, and learning acceleration\n\n### Skills Demonstrated\n- **Systems Programming**: Low-level optimization and memory management in Rust\n- **Algorithm Design**: Implementation of efficient algorithms for complex computational problems\n- **Performance Engineering**: Systematic benchmarking and optimization methodology\n- **Modern Development**: Strategic AI integration for learning, automated testing, and continuous performance monitoring\n\n### Learning Outcomes\nThis project demonstrates my commitment to:\n- **Continuous Learning**: Systematic skill development through challenging programming exercises\n- **Quality Engineering**: Focus on performance, safety, and maintainability\n- **Tool Mastery**: Effective use of modern development tools and strategic AI collaboration for learning\n- **Documentation**: Clear communication of technical concepts and methodologies\n\n---\n\n## 📖 Development Guide\n\nThe following sections provide detailed documentation for using this template and development environment.\n\n## Usage\n\n### ➡️ Scaffold a day\n\n```sh\n# example: `cargo scaffold 1`\ncargo scaffold \u003cday\u003e\n\n# output:\n# Created module file \"src/bin/01.rs\"\n# Created empty input file \"data/inputs/01.txt\"\n# Created empty example file \"data/examples/01.txt\"\n# ---\n# 🎄 Type `cargo solve 01` to run your solution.\n```\n\nIndividual solutions live in the `./src/bin/` directory as separate binaries. _Inputs_ and _examples_ live in the the `./data` directory.\n\nEvery [solution](https://github.com/fspoettel/advent-of-code-rust/blob/main/src/template.txt) 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.\n\n\u003e [!TIP]\n\u003e If a day has multiple example inputs, you can use the `read_file_part()` helper in your tests instead of `read_file()`. If this e.g. applies to day 1, you can create a second example file `01-2.txt` and invoke the helper like `let result = part_two(\u0026advent_of_code::template::read_file_part(\"examples\", DAY, 2));`. This supports an arbitrary number of example files.\n\n### ➡️ Download input for a day\n\n\u003e [!IMPORTANT] \n\u003e This requires [installing the aoc-cli crate](#configure-aoc-cli-integration).\n\nYou 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:\n\n```sh\n# example: `cargo download 1`\ncargo download \u003cday\u003e\n\n# output:\n# [INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool\n# [INFO  aoc_client] 🎅 Saved puzzle to 'data/puzzles/01.md'\n# [INFO  aoc_client] 🎅 Saved input to 'data/inputs/01.txt'\n# ---\n# 🎄 Successfully wrote input to \"data/inputs/01.txt\".\n# 🎄 Successfully wrote puzzle to \"data/puzzles/01.md\".\n```\n\n### ➡️ Run solutions for a day\n\n```sh\n# example: `cargo solve 01`\ncargo solve \u003cday\u003e\n\n# output:\n#     Finished dev [unoptimized + debuginfo] target(s) in 0.13s\n#     Running `target/debug/01`\n# Part 1: 42 (166.0ns)\n# Part 2: 42 (41.0ns)\n```\n\nThe `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.\n\n#### Submitting solutions\n\n\u003e [!IMPORTANT]\n\u003e This requires [installing the aoc-cli crate](#configure-aoc-cli-integration).\n\nAppend the `--submit \u003cpart\u003e` option to the `solve` command to submit your solution for checking.\n\n### ➡️ Run all solutions\n\n```sh\ncargo all\n\n# output:\n#     Running `target/release/advent_of_code`\n# ----------\n# | Day 01 |\n# ----------\n# Part 1: 42 (19.0ns)\n# Part 2: 42 (19.0ns)\n# \u003c...other days...\u003e\n# Total: 0.20ms\n```\n\nThis runs all solutions sequentially and prints output to the command-line. Same as for the `solve` command, the `--release` flag runs an optimized build.\n\n### ➡️ Benchmark your solutions\n\n```sh\n# example: `cargo time 8 --store`\ncargo time \u003cday\u003e [--all] [--store]\n\n# output:\n# Day 08\n# ------\n# Part 1: 1 (39.0ns @ 10000 samples)\n# Part 2: 2 (39.0ns @ 10000 samples)\n#\n# Total (Run): 0.00ms\n#\n# Stored updated benchmarks.\n```\n\nThe `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.\n\n`cargo time` has three modes of execution:\n\n 1. `cargo time` without arguments incrementally benches solutions that do not have been stored in the readme yet and skips the rest.\n 2. `cargo time \u003cday\u003e` benches a single solution.\n 3. `cargo time --all` benches all solutions.\n\nBy default, `cargo time` does not write to the readme. In order to do so, append the `--store` flag: `cargo time --store`.\n\n\u003e 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.\n\n### ➡️ Run all tests\n\n```sh\ncargo test\n```\n\nTo run tests for a specific day, append `--bin \u003cday\u003e`, e.g. `cargo test --bin 01`. You can further scope it down to a specific part, e.g. `cargo test --bin 01 part_one`.\n\n### ➡️ Read puzzle description\n\n\u003e [!IMPORTANT]\n\u003e This command requires [installing the aoc-cli crate](#configure-aoc-cli-integration).\n\n```sh\n# example: `cargo read 1`\ncargo read \u003cday\u003e\n\n# output:\n# Loaded session cookie from \"/Users/\u003csnip\u003e/.adventofcode.session\".\n# Fetching puzzle for day 1, 2022...\n# ...the input...\n```\n\n### ➡️ Scaffold, download \u0026 read the current aoc day\n\n\u003e [!IMPORTANT]\n\u003e This command requires [installing the aoc-cli crate](#configure-aoc-cli-integration).\n\nDuring december, the `today` shorthand command can be used to:\n\n - scaffold a solution for the current day\n - download its input\n - and read the puzzle\n\nin one go.\n\n```sh\n# example: `cargo today` on December 1st\ncargo today\n\n# output:\n# Created module file \"src/bin/01.rs\"\n# Created empty input file \"data/inputs/01.txt\"\n# Created empty example file \"data/examples/01.txt\"\n# ---\n# 🎄 Type `cargo solve 01` to run your solution.\n# [INFO  aoc] 🎄 aoc-cli - Advent of Code command-line tool\n# [INFO  aoc_client] 🎅 Saved puzzle to 'data/puzzles/01.md'\n# [INFO  aoc_client] 🎅 Saved input to 'data/inputs/01.txt'\n# ---\n# 🎄 Successfully wrote input to \"data/inputs/01.txt\".\n# 🎄 Successfully wrote puzzle to \"data/puzzles/01.md\".\n#\n# Loaded session cookie from \"/Users/\u003csnip\u003e/.adventofcode.session\".\n# Fetching puzzle for day 1, 2022...\n# ...the input...\n```\n\n### ➡️ Format code\n\n```sh\ncargo fmt\n```\n\n### ➡️ Lint code\n\n```sh\ncargo clippy\n```\n\n## Optional template features\n\n### Configure aoc-cli integration\n\n1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.12.0`\n2. Create the file `\u003chome_directory\u003e/.adventofcode.session` and paste your session cookie into it. To retrieve the session cookie, press F12 anywhere on the Advent of Code website to open your browser developer tools. Look in _Cookies_ under the _Application_ or _Storage_ tab, and copy out the `session` cookie value. [^1]\n\nOnce installed, you can use the [download command](#download-input--description-for-a-day), the read command, and automatically submit solutions via the [`--submit` flag](#submitting-solutions).\n\n### Automatically track ⭐️ progress in the readme\n\nThis template includes [a Github action](https://github.com/k2bd/advent-readme-stars) that automatically updates the readme with your advent of code progress.\n\nTo enable it, complete the following steps:\n\n#### 1. Create a private leaderboard\n\nGo to the leaderboard page of the year you want to track and click _Private Leaderboard_. If you have not created a leaderboard yet, create one by clicking _Create It_. Your leaderboard should be accessible under `https://adventofcode.com/{year}/leaderboard/private/view/{aoc_user_id}`.\n\n#### 2. Set repository secrets\n\nGo to the _Secrets_ tab in your repository settings and create the following secrets:\n\n-   `AOC_USER_ID`: Go to [this page](https://adventofcode.com/settings) and copy your user id. It's the number behind the `#` symbol in the first name option. Example: `3031`.\n-   `AOC_YEAR`: the year you want to track. Example: `2021`.\n-   `AOC_SESSION`: an active session[^2] for the advent of code website. To get this, press F12 anywhere on the Advent of Code website to open your browser developer tools. Look in your Cookies under the Application or Storage tab, and copy out the `session` cookie.\n\nGo to the _Variables_ tab in your repository settings and create the following variable:\n\n-   `AOC_ENABLED`: This variable controls whether the workflow is enabled. Set it to `true` to enable the progress tracker. After you complete AoC or no longer work on it, you can set this to `false` to disable the CI.\n\n✨ You can now run this action manually via the _Run workflow_ button on the workflow page. If you want the workflow to run automatically, uncomment the `schedule` section in the `readme-stars.yml` workflow file or add a `push` trigger.\n\n### Enable code formatting / clippy checks in the CI\n\nUncomment the respective sections in the `ci.yml` workflow.\n\n### Use DHAT to profile heap allocations\n\nIf you are not only interested in the runtime of your solution, but also its memory allocation profile, you can use the template's [DHAT](https://valgrind.org/docs/manual/dh-manual.html) integration to analyze it. In order to activate DHAT, call the `solve` command with the `--dhat` flag.\n\n```sh\ncargo solve 1 --dhat\n\n# output:\n#     Running `target/dhat/1`\n# dhat: Total:     276 bytes in 3 blocks\n# dhat: At t-gmax: 232 bytes in 2 blocks\n# dhat: At t-end:  0 bytes in 0 blocks\n# dhat: The data has been saved to dhat-heap.json, and is viewable with dhat/dh_view.html\n# Part 1: 9001 (4.1ms)\n```\n\nThe command will output some basic stats to the command-line and generate a `dhat-heap.json` report in the repo root directory.\n\nYou can pass the report a tool like [dh-view](https://nnethercote.github.io/dh_view/dh_view.html) to view a detailed breakdown of heap allocations.\n\n### Use VS Code to debug your code\n\n1.  Install [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) and [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb).\n2.  Set breakpoints in your code. [^3]\n3.  Click _Debug_ next to the unit test or the _main_ function. [^4]\n4.  The debugger will halt your program at the specific line and allow you to inspect the local stack. [^5]\n\n## Useful crates\n\n-   [itertools](https://crates.io/crates/itertools): Extends iterators with extra methods and adaptors. Frequently useful for aoc puzzles.\n-   [regex](https://crates.io/crates/regex): Official regular expressions implementation for Rust.\n\nA curated list of popular crates can be found on [blessed.rs](https://blessed.rs/crates).\n\nDo you have aoc-specific crate recommendations? [Share them!](https://github.com/fspoettel/advent-of-code-rust/edit/main/README.md)\n\n## Footnotes\n\n[^1]: The session cookie might expire after a while (~1 month) which causes the downloads to fail. To fix this issue, refresh the `.adventofcode.session` file.\n[^2]: The session cookie might expire after a while (~1 month) which causes the automated workflow to fail. To fix this issue, refresh the AOC_SESSION secret.\n[^3]:\n    \u003cimg src=\"https://user-images.githubusercontent.com/1682504/198838369-453dc22c-c645-4803-afe0-fc50d5a3f00c.png\" alt=\"Set a breakpoint\" width=\"450\" /\u003e\n\n[^4]:\n    \u003cimg alt=\"Run debugger\" src=\"https://user-images.githubusercontent.com/1682504/198838372-c89369f6-0d05-462e-a4c7-8cd97b0912e6.png\" width=\"450\" /\u003e\n\n[^5]:\n    \u003cimg alt=\"Inspect debugger state\" src=\"https://user-images.githubusercontent.com/1682504/198838373-36df6996-23bf-4757-9335-0bc4c1db0276.png\" width=\"450\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoook%2Faoc-rust-2024","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoook%2Faoc-rust-2024","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoook%2Faoc-rust-2024/lists"}