Implement 2025 - Day 2 - Part 1

This commit is contained in:
Lol3rrr
2026-01-08 20:24:22 +01:00
parent 4347fb2131
commit c7ad6b02a8
3 changed files with 38 additions and 0 deletions

36
2025/02.rs Normal file
View File

@@ -0,0 +1,36 @@
---cargo
---
static CONTENT: &'static str = include_str!("./inputs/02_1.txt");
fn main() {
let ranges: Vec<_> = CONTENT.split(',').map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
let (raw_start, raw_end) = l.split_once('-').unwrap();
let start: usize = raw_start.parse().unwrap();
let end: usize = raw_end.parse().unwrap();
start..=end
}).collect();
println!("Ranges: {:?}", ranges);
let mut result = 0;
for r in ranges.iter() {
for v in r.clone() {
let len = v.ilog10() + 1;
if len % 2 != 0 {
continue;
}
let first_half = v / 10_usize.pow(len/2);
let second_half = v - (first_half * 10_usize.pow(len/2));
if first_half == second_half {
result += v;
println!("Invalid {} - Halves ({}, {})", v, first_half, second_half);
}
}
}
println!("Result: {}", result);
}