add day 20

This commit is contained in:
timeshifter
2026-06-25 22:51:27 +02:00
parent f6e4d9cea0
commit 7d087a5c14
3 changed files with 58 additions and 0 deletions
+45
View File
@@ -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;
}
}
}