Skip to content

Commit 4449f5b

Browse files
committed
initial commit
0 parents  commit 4449f5b

File tree

19 files changed

+531
-0
lines changed

19 files changed

+531
-0
lines changed

.cargo/config

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
rustflags = ["-C", "target-cpu=native"]
3+
4+
[alias]
5+
rr = "run --release"

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
indent_size = 4
6+
indent_style = space
7+
end_of_line = lf
8+
charset = utf-8
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.txt]
13+
insert_final_newline = false
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.github/workflows/readme-stars.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Update README ⭐
2+
on:
3+
schedule:
4+
- cron: "51 */4 * * *" # Every 4 hours
5+
workflow_dispatch:
6+
7+
jobs:
8+
update-readme:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: k2bd/advent-readme-stars@v1
13+
with:
14+
userId: ${{ secrets.AOC_USER_ID }}
15+
sessionCookie: ${{ secrets.AOC_SESSION }}
16+
year: ${{ secrets.AOC_YEAR }}
17+
- uses: stefanzweifel/git-auto-commit-action@v4
18+
with:
19+
commit_message: Update README stars

.github/workflows/rust.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Build
20+
run: cargo build --verbose
21+
- name: Run tests
22+
run: cargo test --verbose

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# These are backup files generated by rustfmt
7+
**/*.rs.bk
8+
9+
# MSVC Windows builds of rustc generate these, which store debugging information
10+
*.pdb
11+
12+
13+
# Added by cargo
14+
15+
/target
16+
17+
# Advent of Code
18+
# @see https://old.reddit.com/r/adventofcode/comments/k99rod/sharing_input_data_were_we_requested_not_to/gf2ukkf/?context=3
19+
inputs
20+
!inputs/.keep

.vscode/launch.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug unit tests in executable 'aoc'",
11+
"cargo": {
12+
"args": [
13+
"test",
14+
"--no-run",
15+
"--bin=aoc",
16+
"--package=aoc"
17+
],
18+
"filter": {
19+
"name": "aoc",
20+
"kind": "bin"
21+
}
22+
},
23+
"args": [],
24+
"cwd": "${workspaceFolder}"
25+
},
26+
{
27+
"type": "lldb",
28+
"request": "launch",
29+
"name": "Debug executable 'aoc'",
30+
"cargo": {
31+
"args": [
32+
"build",
33+
"--bin=aoc",
34+
"--package=aoc"
35+
],
36+
"filter": {
37+
"name": "aoc",
38+
"kind": "bin"
39+
}
40+
},
41+
"args": ["1"],
42+
"cwd": "${workspaceFolder}"
43+
},
44+
{
45+
"type": "lldb",
46+
"request": "launch",
47+
"name": "Debug unit tests in library 'aoc'",
48+
"cargo": {
49+
"args": [
50+
"test",
51+
"--no-run",
52+
"--lib",
53+
"--package=aoc"
54+
],
55+
"filter": {
56+
"name": "aoc",
57+
"kind": "lib"
58+
}
59+
},
60+
"args": [],
61+
"cwd": "${workspaceFolder}"
62+
}
63+
]
64+
}

Cargo.lock

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "aoc"
3+
version = "0.1.0"
4+
authors = ["Felix Spöttel <[email protected]>"]
5+
edition = "2021"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[profile.release]
10+
lto = "thin"
11+
12+
[dependencies]
13+
itertools = "0.10.1"

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Felix Spoettel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<img src="./assets/christmas_ferris.png" width="164" align="center">
2+
3+
# 🎄 [Advent of Code](https://adventofcode.com/)
4+
5+
![Language](https://badgen.net/badge/Language/Rust/orange)
6+
7+
<!--- advent_readme_stars table --->
8+
9+
---
10+
11+
Generated with the [advent-of-code-rust](https://github.com/fspoettel/advent-of-code-rust) template.
12+
13+
## Create your own
14+
15+
1. Open the [advent-of-code-rust](https://github.com/fspoettel/advent-of-code-rust) template on Github.
16+
2. Click `Use this template` and create your repository.
17+
3. Clone the repository to your machine.
18+
19+
## Install
20+
21+
* Install the [Rust toolchain](https://www.rust-lang.org/tools/install).
22+
* (optional) Install [rust-analyzer](https://rust-analyzer.github.io/manual.html) for your editor.
23+
* (optional) Install a native debugger, e.g. [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) for VS Code.
24+
* (optional) Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) and follow their setup guide to use the `download` script for puzzle inputs. (see below)
25+
* (optional) Setup the README stars github action. (see below)
26+
27+
## Commands
28+
29+
### Setup new day
30+
31+
```sh
32+
# example: `./scripts/scaffold.sh 1`
33+
./scripts/scaffold.sh <day>
34+
35+
# output:
36+
# Created module `src/solutions/day01.rs`
37+
# Created input file `src/inputs/day01.txt`
38+
# Created example file `src/examples/day01.txt`
39+
# Linked new module in `src/main.rs`
40+
# Linked new module in `src/solutions/mod.rs`
41+
# Done! 🎄
42+
```
43+
44+
Every solution file has _unit tests_ referencing the example input file. You can use these tests to develop and debug your solution. When editing a solution file, `rust-analyzer` will display buttons for these actions above the unit tests.
45+
46+
### Download inputs for a day
47+
48+
```sh
49+
# example: `./scripts/download.sh 1`
50+
./scripts/download.sh <day>
51+
52+
# output:
53+
# Invoking `aoc` cli...
54+
# Loaded session cookie from "/home/foo/.adventofcode.session".
55+
# Downloading input for day 1, 2021...
56+
# Saving puzzle input to "/tmp/..."...
57+
# Done!
58+
# Wrote input to `src/inputs/day01.txt`...
59+
# Done! 🎄
60+
```
61+
62+
Puzzle inputs are not checked into git. [See here](https://old.reddit.com/r/adventofcode/comments/k99rod/sharing_input_data_were_we_requested_not_to/gf2ukkf/?context=3) why.
63+
64+
### Run solutions for a day
65+
66+
```sh
67+
# example: `cargo run 1`
68+
cargo run <day>
69+
70+
# output:
71+
# Running `target/debug/aoc 1`
72+
# ----
73+
#
74+
# 🎄 Part 1 🎄
75+
#
76+
# 6 (elapsed: 37.03µs)
77+
#
78+
# 🎄 Part 2 🎄
79+
#
80+
# 9 (elapsed: 33.18µs)
81+
#
82+
# ----
83+
```
84+
85+
To run an optimized version for benchmarking, use the `--release` flag or the alias `cargo rr <day>`.
86+
87+
### Run all solutions against example input
88+
89+
```sh
90+
cargo test
91+
```
92+
93+
### Format code
94+
95+
```sh
96+
cargo fmt
97+
```
98+
99+
### Lint code
100+
101+
```sh
102+
cargo clippy
103+
```
104+
105+
## Setup readme stars
106+
107+
This template includes [a Github action](https://github.com/k2bd/advent-readme-stars) that automatically updates the readme with your advent of code progress.
108+
109+
To enable it, you need to do two things:
110+
111+
1. set repository secrets.
112+
2. create a private leaderboard.
113+
114+
### Repository secrets
115+
116+
Go to the _Secrets_ tab in your repository settings and create the following secrets:
117+
118+
* `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`
119+
* `AOC_YEAR`: the year you want to track. Example: `2021`
120+
* `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.
121+
122+
### Private Leaderboard
123+
124+
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}`.

assets/banner.png

61.3 KB
Loading

assets/christmas_ferris.png

70.4 KB
Loading

scripts/download.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e;
4+
5+
if ! command -v 'aoc' &> /dev/null
6+
then
7+
echo "command \`aoc\` not found. Try running \`cargo install aoc-cli\` to install it."
8+
exit 1
9+
fi
10+
11+
if [ ! -n "$1" ]; then
12+
>&2 echo "Argument is required for day."
13+
exit 1
14+
fi
15+
16+
day=$(echo $1 | sed 's/^0*//');
17+
day_padded=`printf %02d $day`;
18+
19+
filename="day$day_padded";
20+
input_path="src/inputs/$filename.txt";
21+
22+
tmp_dir=$(mktemp -d);
23+
tmp_file_path="$tmp_dir/input";
24+
25+
aoc download --day $day --file $tmp_file_path;
26+
cat $tmp_file_path > $input_path;
27+
echo "Wrote input to \"$input_path\"...";
28+
29+
cat <<EOF
30+
_==_ _
31+
_,(",)|_|
32+
\/. \-|
33+
__( : )|_ Done!
34+
EOF
35+
36+
# Make sure it gets removed even if the script exits abnormally.
37+
trap "exit 1" HUP INT PIPE QUIT TERM
38+
trap 'rm -rf "$tmp_dir"' EXIT

0 commit comments

Comments
 (0)