add: d05 & debug utils

- includes a script to generate a 2GB big challenge
- added utils to internally time functions with minimal overhead
- add functionality to tester.rs
This commit is contained in:
2025-12-05 22:11:15 +01:00
parent 3f64295fb5
commit da7ab076f2
7 changed files with 497 additions and 17 deletions

40
2025/05/p2-hu.rs Normal file
View File

@@ -0,0 +1,40 @@
pub type RangeU = usize;
#[unsafe(no_mangle)]
extern "Rust" fn challenge_usize(buf: &[u8]) -> usize {
let s = unsafe { str::from_utf8_unchecked(buf) };
let mut lines = s.lines();
let mut count = 0;
let mut ranges: Vec<(RangeU, RangeU)> = Vec::new();
for range in &mut lines {
if range.is_empty() {
break;
}
let (l, r) = range.split_once('-').unwrap();
let (l, r) = (l.parse().unwrap(), r.parse().unwrap());
// overlapping here means overlapping or adyacent
count += r - l + 1;
let overlapping: Option<&mut (RangeU, RangeU)> = None;
for (r_l, r_r) in ranges.iter_mut() {
if l <= *r_r && r >= *r_r {
*r_r = r;
//
}
// (|(l, r)| (l..=r).contains(&fresh))
}
for fresh in l..=r {
println!("{fresh:?}");
if ranges.iter().any(|&(l, r)| (l..=r).contains(&fresh)) {
count -= 1;
}
}
ranges.push((l, r));
}
count
}