diff --git a/Cargo.lock b/Cargo.lock index ce2f70b..5afdad8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,9 +394,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.5.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" +checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" [[package]] name = "itertools" @@ -716,9 +716,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.149" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" +checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91" [[package]] name = "serde_json" diff --git a/src/bin/20.rs b/src/bin/20.rs new file mode 100644 index 000000000..5e2e5e1 --- /dev/null +++ b/src/bin/20.rs @@ -0,0 +1,43 @@ +pub fn part_one(input: &str) -> Option { + let limit = input.parse::().unwrap() / 10; + let elves = 1_000_000; + let mut delivered = vec![0; elves]; + for i in 1..elves { + for j in (i..elves).step_by(i) { + delivered[j] += i; + } + } + + Some( + delivered + .iter() + .enumerate() + .find(|(_, &x)| x > limit) + .unwrap() + .0 as u32, + ) +} +pub fn part_two(input: &str) -> Option { + let limit = input.parse().unwrap(); + let elves = 1_000_000; + let mut delivered = vec![0; elves]; + for i in 1..elves { + for j in (i..elves).step_by(i).take(50) { + delivered[j] += i * 11; + } + } + + Some( + delivered + .iter() + .enumerate() + .find(|(_, &x)| x > limit) + .unwrap() + .0 as u32, + ) +} +fn main() { + let input = &aoc::read_file("inputs", 20); + aoc::solve!(1, part_one, input); + aoc::solve!(2, part_two, input); +} diff --git a/src/test_inputs/20.txt b/src/test_inputs/20.txt new file mode 100644 index 000000000..e69de29