diff --git a/day20/Cargo.lock b/day20/Cargo.lock new file mode 100644 index 0000000..a18135b --- /dev/null +++ b/day20/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day20" +version = "0.1.0" diff --git a/day20/Cargo.toml b/day20/Cargo.toml new file mode 100644 index 0000000..9a5d286 --- /dev/null +++ b/day20/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day20" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/day20/src/main.rs b/day20/src/main.rs new file mode 100644 index 0000000..2c2aa98 --- /dev/null +++ b/day20/src/main.rs @@ -0,0 +1,45 @@ +const LIMIT: i64 = 36_000_000; + +fn main() { + let input = 1_000_000; + + part1(input); // 831600 + part2(input); // 110880 too low +} + +fn part1(input: i64) { + let mut result = vec![0_i64; input as usize]; + + for i in 1..input { + for j in (i..input).step_by(i as usize) { + result[j as usize] += 10 * i; + } + } + + for (i, value) in result.iter().enumerate() { + if value > &LIMIT { + println!("{i}"); + break; + } + } +} + +fn part2(input: i64) { + let mut result = vec![0_i64; input as usize]; + + for i in 1..input { + for j in (i..=50 * i) + .step_by(i as usize) + .take_while(|idx| *idx < input) + { + result[j as usize] += 11 * i; + } + } + + for (i, value) in result.iter().enumerate() { + if value > &LIMIT { + println!("{i}"); + break; + } + } +}