-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
95 changed files
with
3,946 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[build] | ||
rustflags = ["-C", "target-cpu=native"] | ||
|
||
[alias] | ||
rr = "run --release" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
root = true | ||
|
||
[*] | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.txt] | ||
insert_final_newline = false | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
|
||
# Added by cargo | ||
|
||
/target | ||
|
||
# Advent of Code | ||
# @see https://old.reddit.com/r/adventofcode/comments/k99rod/sharing_input_data_were_we_requested_not_to/gf2ukkf/?context=3 | ||
inputs | ||
!inputs/.keep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug unit tests in executable 'aoc'", | ||
"cargo": { | ||
"args": [ | ||
"test", | ||
"--no-run", | ||
"--bin=aoc", | ||
"--package=aoc" | ||
], | ||
"filter": { | ||
"name": "aoc", | ||
"kind": "bin" | ||
} | ||
}, | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug executable 'aoc'", | ||
"cargo": { | ||
"args": [ | ||
"build", | ||
"--bin=aoc", | ||
"--package=aoc" | ||
], | ||
"filter": { | ||
"name": "aoc", | ||
"kind": "bin" | ||
} | ||
}, | ||
"args": ["1"], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug unit tests in library 'aoc'", | ||
"cargo": { | ||
"args": [ | ||
"test", | ||
"--no-run", | ||
"--lib", | ||
"--package=aoc" | ||
], | ||
"filter": { | ||
"name": "aoc", | ||
"kind": "lib" | ||
} | ||
}, | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "aoc" | ||
version = "0.1.0" | ||
authors = ["Felix Spöttel <[email protected]>"] | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[profile.release] | ||
lto = "thin" | ||
|
||
[dependencies] | ||
itertools = "0.10.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Felix Spoettel | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<img src="./assets/christmas_ferris.png" width="164" align="center"> | ||
|
||
# 🎄 [Advent of Code](https://adventofcode.com/) | ||
|
||
![Language](https://badgen.net/badge/Language/Rust/orange) | ||
|
||
<!--- advent_readme_stars table ---> | ||
|
||
## 2022 Results | ||
|
||
| Day | Part 1 | Part 2 | | ||
| :--------------------------------------------: | :----: | :----: | | ||
| [Day 1](https://adventofcode.com/2021/day/1) | ⭐ | ⭐ | | ||
| [Day 2](https://adventofcode.com/2021/day/2) | ⭐ | ⭐ | | ||
| [Day 3](https://adventofcode.com/2021/day/3) | ⭐ | ⭐ | | ||
| [Day 4](https://adventofcode.com/2021/day/4) | ⭐ | ⭐ | | ||
| [Day 5](https://adventofcode.com/2021/day/5) | ⭐ | ⭐ | | ||
| [Day 6](https://adventofcode.com/2021/day/6) | ⭐ | ⭐ | | ||
| [Day 7](https://adventofcode.com/2021/day/7) | ⭐ | ⭐ | | ||
| [Day 8](https://adventofcode.com/2021/day/8) | ⭐ | ⭐ | | ||
| [Day 9](https://adventofcode.com/2021/day/9) | ⭐ | ⭐ | | ||
| [Day 10](https://adventofcode.com/2021/day/10) | ⭐ | ⭐ | | ||
| [Day 11](https://adventofcode.com/2021/day/11) | ⭐ | ⭐ | | ||
| [Day 12](https://adventofcode.com/2021/day/12) | ⭐ | ⭐ | | ||
| [Day 13](https://adventofcode.com/2021/day/13) | ⭐ | ⭐ | | ||
| [Day 14](https://adventofcode.com/2021/day/14) | ⭐ | ⭐ | | ||
| [Day 15](https://adventofcode.com/2021/day/15) | ⭐ | ⭐ | | ||
| [Day 16](https://adventofcode.com/2021/day/16) | ⭐ | ⭐ | | ||
| [Day 17](https://adventofcode.com/2021/day/17) | ⭐ | ⭐ | | ||
| [Day 18](https://adventofcode.com/2021/day/18) | ⭐ | ⭐ | | ||
| [Day 19](https://adventofcode.com/2021/day/19) | ⭐ | ⭐ | | ||
| [Day 20](https://adventofcode.com/2021/day/20) | ⭐ | ⭐ | | ||
| [Day 21](https://adventofcode.com/2021/day/21) | ⭐ | ⭐ | | ||
| [Day 22](https://adventofcode.com/2021/day/22) | ⭐ | ⭐ | | ||
| [Day 23](https://adventofcode.com/2021/day/23) | ⭐ | ⭐ | | ||
| [Day 24](https://adventofcode.com/2021/day/24) | ⭐ | ⭐ | | ||
| [Day 25](https://adventofcode.com/2021/day/25) | ⭐ | ⭐ | | ||
|
||
<!--- advent_readme_stars table ---> | ||
|
||
--- | ||
|
||
Generated with the [advent-of-code-rust](https://github.com/fspoettel/advent-of-code-rust) template. | ||
|
||
## Commands | ||
|
||
### Setup new day | ||
|
||
```sh | ||
# example: `./scripts/scaffold.sh 1` | ||
./scripts/scaffold.sh <day> | ||
|
||
# output: | ||
# Created module `src/solutions/day01.rs` | ||
# Created input file `src/inputs/day01.txt` | ||
# Created example file `src/examples/day01.txt` | ||
# Linked new module in `src/main.rs` | ||
# Linked new module in `src/solutions/mod.rs` | ||
# Done! 🎄 | ||
``` | ||
|
||
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. | ||
|
||
### Download inputs for a day | ||
|
||
```sh | ||
# example: `./scripts/download.sh 1` | ||
./scripts/download.sh <day> | ||
|
||
# output: | ||
# Invoking `aoc` cli... | ||
# Loaded session cookie from "/home/foo/.adventofcode.session". | ||
# Downloading input for day 1, 2021... | ||
# Saving puzzle input to "/tmp/..."... | ||
# Done! | ||
# Wrote input to `src/inputs/day01.txt`... | ||
# Done! 🎄 | ||
``` | ||
|
||
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. | ||
|
||
### Run solutions for a day | ||
|
||
```sh | ||
# example: `cargo run 1` | ||
cargo run <day> | ||
|
||
# output: | ||
# Running `target/debug/aoc 1` | ||
# ---- | ||
# | ||
# 🎄 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 <day>`. | ||
|
||
### Run all solutions against example input | ||
|
||
```sh | ||
cargo test | ||
``` | ||
|
||
### Format code | ||
|
||
```sh | ||
cargo fmt | ||
``` | ||
|
||
### Lint code | ||
|
||
```sh | ||
cargo clippy | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
set -e; | ||
|
||
if ! command -v 'aoc' &> /dev/null | ||
then | ||
echo "command \`aoc\` not found. Try running \`cargo install aoc-cli\` to install it." | ||
exit 1 | ||
fi | ||
|
||
if [ ! -n "$1" ]; then | ||
>&2 echo "Argument is required for day." | ||
exit 1 | ||
fi | ||
|
||
day=$(echo $1 | sed 's/^0*//'); | ||
day_padded=`printf %02d $day`; | ||
|
||
filename="day$day_padded"; | ||
input_path="src/inputs/$filename.txt"; | ||
|
||
tmp_dir=$(mktemp -d); | ||
tmp_file_path="$tmp_dir/input"; | ||
|
||
aoc download --day $day --file $tmp_file_path; | ||
cat $tmp_file_path > $input_path; | ||
echo "Wrote input to \"$input_path\"..."; | ||
|
||
cat <<EOF | ||
_==_ _ | ||
_,(",)|_| | ||
\/. \-| | ||
__( : )|_ Done! | ||
EOF | ||
|
||
# Make sure it gets removed even if the script exits abnormally. | ||
trap "exit 1" HUP INT PIPE QUIT TERM | ||
trap 'rm -rf "$tmp_dir"' EXIT |
Oops, something went wrong.