From 56f39b5c3c9aa08f2d4e65b8d2fde0065b7c53b3 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 3 Dec 2023 15:14:43 +0100 Subject: [PATCH] script --- .gitignore | 3 ++- 2023/day00/Cargo.toml | 15 +++++++++++ 2023/day00/benches/benches.rs | 3 +++ 2023/day00/input.txt | 0 2023/day00/input_small.txt | 0 2023/day00/src/lib.rs | 48 +++++++++++++++++++++++++++++++++++ 2023/day00/src/main.rs | 3 +++ 2023/day01/src/naive.rs | 4 +-- 2023/day01/src/zero_alloc.rs | 4 +-- Cargo.lock | 18 +++++++++++++ aoc.sh | 27 ++++++++++++++++++++ 11 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 2023/day00/Cargo.toml create mode 100644 2023/day00/benches/benches.rs create mode 100644 2023/day00/input.txt create mode 100644 2023/day00/input_small.txt create mode 100644 2023/day00/src/lib.rs create mode 100644 2023/day00/src/main.rs create mode 100755 aoc.sh diff --git a/.gitignore b/.gitignore index ed9af90..afd7e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target -perf.data* \ No newline at end of file +perf.data* +aoc_cookie diff --git a/2023/day00/Cargo.toml b/2023/day00/Cargo.toml new file mode 100644 index 0000000..2442087 --- /dev/null +++ b/2023/day00/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "day00" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +nom.workspace = true +helper.workspace = true +divan.workspace = true + +[[bench]] +name = "benches" +harness = false diff --git a/2023/day00/benches/benches.rs b/2023/day00/benches/benches.rs new file mode 100644 index 0000000..d6e3cbf --- /dev/null +++ b/2023/day00/benches/benches.rs @@ -0,0 +1,3 @@ +fn main() { + day00::bench(); +} diff --git a/2023/day00/input.txt b/2023/day00/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/2023/day00/input_small.txt b/2023/day00/input_small.txt new file mode 100644 index 0000000..e69de29 diff --git a/2023/day00/src/lib.rs b/2023/day00/src/lib.rs new file mode 100644 index 0000000..91c428a --- /dev/null +++ b/2023/day00/src/lib.rs @@ -0,0 +1,48 @@ +use helper::{Day, Variants}; + +pub fn main() { + helper::main::(include_str!("../input.txt")); +} + +struct Day00; + +helper::define_variants! { + day => crate::Day00; + part1 { + basic => crate::part1; + } + part2 { + basic => crate::part2; + } +} + +impl Day for Day00 { + fn part1() -> Variants { + part1_variants!(construct_variants) + } + + fn part2() -> Variants { + part2_variants!(construct_variants) + } +} + +fn part1(_input: &str) -> u64 { + 0 +} + +fn part2(_input: &str) -> u64 { + 0 +} + +helper::tests! { + day00 Day00; + part1 { + small => 8; + default => 1931; + } + part2 { + small => 2286; + default => 83105; + } +} +helper::benchmarks! {} diff --git a/2023/day00/src/main.rs b/2023/day00/src/main.rs new file mode 100644 index 0000000..ee73e76 --- /dev/null +++ b/2023/day00/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + day00::main(); +} diff --git a/2023/day01/src/naive.rs b/2023/day01/src/naive.rs index 3b74b79..b9f2d3a 100644 --- a/2023/day01/src/naive.rs +++ b/2023/day01/src/naive.rs @@ -24,5 +24,5 @@ pub fn part2(input: &str) -> u64 { }) .sum::(); - sum - } + sum +} diff --git a/2023/day01/src/zero_alloc.rs b/2023/day01/src/zero_alloc.rs index 8f5b2d2..f30b54f 100644 --- a/2023/day01/src/zero_alloc.rs +++ b/2023/day01/src/zero_alloc.rs @@ -39,5 +39,5 @@ pub fn part2(input: &str) -> u64 { }) .sum::(); - sum - } + sum +} diff --git a/Cargo.lock b/Cargo.lock index 176ee3d..dc9309f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,6 +96,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" +[[package]] +name = "day00" +version = "0.1.0" +dependencies = [ + "divan", + "helper", + "nom", +] + [[package]] name = "day01" version = "0.1.0" @@ -122,6 +131,15 @@ dependencies = [ "nom", ] +[[package]] +name = "day04" +version = "0.1.0" +dependencies = [ + "divan", + "helper", + "nom", +] + [[package]] name = "divan" version = "0.1.4" diff --git a/aoc.sh b/aoc.sh new file mode 100755 index 0000000..3522ad5 --- /dev/null +++ b/aoc.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -eu + +function get_cookie { + if [ ! -f aoc_cookie ]; then + echo "aoc_cookie file not found, cannot download" >&2 + exit 1 + fi + cat aoc_cookie +} + +: "${1:?usage: ./aoc.sh new}" + +case "$1" in + new) + : "${2:?usage: ./aoc.sh new DAY}" + day="$(printf %02d "$2")" + cp -r "2023/day00" "2023/day$day" + find "2023/day$day" -type f -exec sed -i -e "s/00/$day/g" {} \; + + curl -H "Cookie: $(get_cookie)" "https://adventofcode.com/2023/day/$2/input" -o "2023/day$day/input.txt" + ;; + *) + echo "usage: ./aoc.sh new" >&2 + ;; +esac