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);
}

1
2025/inputs/02_1.txt Normal file
View File

@@ -0,0 +1 @@
17330-35281,9967849351-9967954114,880610-895941,942-1466,117855-209809,9427633930-9427769294,1-14,311209-533855,53851-100089,104-215,33317911-33385573,42384572-42481566,43-81,87864705-87898981,258952-303177,451399530-451565394,6464564339-6464748782,1493-2439,9941196-10054232,2994-8275,6275169-6423883,20-41,384-896,2525238272-2525279908,8884-16221,968909030-969019005,686256-831649,942986-986697,1437387916-1437426347,8897636-9031809,16048379-16225280

View File

@@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124