aoc2022/README.md

4.2 KiB

🎄 Advent of Code

Language


Generated with the advent-of-code-rust template.

Create your own

  1. Open the advent-of-code-rust template on Github.
  2. Click Use this template and create your repository.
  3. Clone the repository to your machine.

Install

  • Install the Rust toolchain.
  • (optional) Install rust-analyzer for your editor.
  • (optional) Install a native debugger, e.g. CodeLLDB for VS Code.
  • (optional) Install aoc-cli and follow their setup guide to use the download script for puzzle inputs. (see below)
  • (optional) Setup the README stars github action. (see below)

Commands

Setup new day

# example: `./scripts/scaffold.sh 1`
./scripts/scaffold.sh <day>

# output:
# Created module "src/bin/01.rs"
# Created empty input file "src/inputs/01.txt"
# Created empty example file "src/examples/01.txt"
# ---
# 🎄 Type `cargo run --bin 01` to run your solution.

Every solution has unit tests referencing the example file. Use these tests to develop and debug your solution. When editing a solution, rust-analyzer will display buttons for these actions above the unit tests.

Download inputs for a day

# example: `./scripts/download.sh 1`
./scripts/download.sh <day>

# output:
# Loaded session cookie from "/home/felix/.adventofcode.session".
# Downloading input for day 1, 2021...
# Saving puzzle input to "/tmp/tmp.MBdcAdL9Iw/input"...
# Done!
# ---
# 🎄 Successfully wrote input to "src/inputs/01.txt"!

Puzzle inputs are not checked into git. See here why.

This script does not support downloading inputs for previous years. If you want to use this template for a previous aoc, use the underlying aoc-cli binary directly or download your inputs manually.

Run solutions for a day

# example: `cargo run --bin 01`
cargo run --bin <day>

# output:
#     Running `target/debug/01`
# 🎄 Part 1 🎄
#
# 6 (elapsed: 37.03µs)
#
# 🎄 Part 2 🎄
#
# 9 (elapsed: 33.18µs)

To run an optimized version for benchmarking, use the --release flag or the alias cargo rr --bin <day>.

Run all solutions

cargo run

To run an optimized version for benchmarking, use the --release flag or the alias cargo rr.

Run all solutions against example input

cargo test

Format code

cargo fmt

Lint code

cargo clippy

Setup readme stars

This template includes a Github action that automatically updates the readme with your advent of code progress.

To enable it, you need to do two things:

  1. set repository secrets.
  2. create a private leaderboard.

Repository secrets

Go to the Secrets tab in your repository settings and create the following secrets:

  • AOC_USER_ID: Go to this page and copy your user id. It's the number behind the # symbol in the first name option. Example: 3031
  • AOC_YEAR: the year you want to track. Example: 2021
  • AOC_SESSION: an active session 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.

Private Leaderboard

Go 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}.