diff --git a/.gitignore b/.gitignore index 3ca43ae..044fbed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ +.history/ # ---> Rust # Generated by Cargo # will have compiled files and executables debug/ target/ + # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html Cargo.lock @@ -14,3 +16,5 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb +# AoC +input/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..60c494b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc_2022" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aoc-runner = "0.3.0" +aoc-runner-derive = "0.3.0" \ No newline at end of file diff --git a/src/day01.rs b/src/day01.rs new file mode 100644 index 0000000..41d20bb --- /dev/null +++ b/src/day01.rs @@ -0,0 +1,19 @@ +use std::cmp::Reverse; + +use aoc_runner_derive::{aoc, aoc_generator}; +#[aoc_generator(day1)] +pub fn input_generator(input: &str) -> Vec { + input.split("\n\n").map(|chunk| chunk.lines().map(|line| line.trim().parse::().unwrap()).sum()).collect() +} + +#[aoc(day1, part1)] +pub fn solve_part1(input: &[usize]) -> usize { + input.iter().max().copied().unwrap_or(0) +} + +#[aoc(day1, part2)] +pub fn solve_part2(input: &[usize]) -> usize { + let mut scores: Vec = input.to_vec(); + scores.sort_by_key(|v| Reverse(*v)); + scores.iter().take(3).sum() +} diff --git a/src/dayXX.rs b/src/dayXX.rs new file mode 100644 index 0000000..bb03e4b --- /dev/null +++ b/src/dayXX.rs @@ -0,0 +1,15 @@ +use aoc_runner_derive::{aoc, aoc_generator}; +#[aoc_generator(dayX)] +pub fn input_generator(input: &str) -> _ { + todo!() +} + +#[aoc(dayX, part1)] +pub fn solve_part1(input: &[usize]) -> _ { + todo!() +} + +// #[aoc(dayX, part2)] +// pub fn solve_part2(input: &[usize]) -> _ { +// todo!() +// } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..0d9c6bf --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,4 @@ + +use aoc_runner_derive::aoc_lib; +pub mod day01; +aoc_lib! { year = 2022 } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5ed4bad --- /dev/null +++ b/src/main.rs @@ -0,0 +1,2 @@ +use aoc_runner_derive::aoc_main; +aoc_main! { lib = aoc_2022 }