commit 2685989a89c7eb8915ae17417a74b42e599abe00 Author: pjht Date: Thu Dec 1 11:17:42 2022 -0600 Day 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1033ab7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/Cargo.lock +/input diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..04b351e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc2022" +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" diff --git a/src/day01.rs b/src/day01.rs new file mode 100644 index 0000000..e7cd061 --- /dev/null +++ b/src/day01.rs @@ -0,0 +1,35 @@ +use aoc_runner_derive::{aoc, aoc_generator}; + +#[aoc_generator(day1)] +pub fn input_generator(input: &str) -> Vec> { + input + .lines() + .collect::>() + .split(|el| el == &"") + .map(|list| { + list.iter() + .map(|el| el.parse::().unwrap()) + .collect::>() + }) + .collect::>() +} + +#[aoc(day1, part1)] +pub fn solve_part1(input: &[Vec]) -> u64 { + let mut sums = input + .iter() + .map(|el| el.iter().sum::()) + .collect::>(); + sums.sort(); + sums.pop().unwrap() +} + +#[aoc(day1, part2)] +pub fn solve_part2(input: &[Vec]) -> u64 { + let mut sums = input + .iter() + .map(|el| el.iter().sum::()) + .collect::>(); + sums.sort(); + sums[sums.len() - 3..sums.len()].iter().sum::() +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..5d1048b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +use aoc_runner_derive::aoc_lib; + +pub mod day01; + +aoc_lib! { year = 2022 }