Implement AoC 2025 #1
37
2025/05.rs
Normal file
37
2025/05.rs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
---cargo
|
||||||
|
---
|
||||||
|
|
||||||
|
static CONTENT: &'static str = include_str!("./inputs/05_1.txt");
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut ranges: Vec<_> = CONTENT.lines().map(|l| l.trim()).take_while(|l| !l.is_empty()).map(|r| {
|
||||||
|
let (start, end) = r.split_once('-').unwrap();
|
||||||
|
let start = start.parse::<usize>().unwrap();
|
||||||
|
let end = end.parse::<usize>().unwrap();
|
||||||
|
|
||||||
|
start..=end
|
||||||
|
}).collect();
|
||||||
|
println!("Ranges: {:?}", ranges);
|
||||||
|
|
||||||
|
ranges.sort_by_key(|v| *v.start());
|
||||||
|
println!("Ranges: {:?}", ranges);
|
||||||
|
|
||||||
|
let ids: Vec<_> = CONTENT.lines().map(|l| l.trim()).skip_while(|l| !l.is_empty()).skip(1).map(|v| v.parse::<usize>().unwrap()).collect();
|
||||||
|
println!("IDs: {:?}", ids);
|
||||||
|
|
||||||
|
|
||||||
|
let fresh = ids.iter().filter(|id| {
|
||||||
|
for r in ranges.iter() {
|
||||||
|
if r.start() > id {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.contains(id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}).count();
|
||||||
|
println!("Fresh: {:?}", fresh);
|
||||||
|
}
|
||||||
1191
2025/inputs/05_1.txt
Normal file
1191
2025/inputs/05_1.txt
Normal file
File diff suppressed because it is too large
Load Diff
11
2025/inputs/05_example.txt
Normal file
11
2025/inputs/05_example.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
Reference in New Issue
Block a user