aoc2022/examples/day04_2.rs

13 lines
478 B
Rust
Raw Normal View History

2022-12-04 05:07:16 +00:00
fn main() {
let lines: Vec<String> = std::io::stdin().lines().map(|x| x.unwrap()).collect();
let mut result = 0;
for line in lines {
let elves = line.split(",").map(|x| x.split("-").map(|s| s.parse().unwrap()).collect()).collect::<Vec<Vec<i32>>>();
if elves[0][1] >= elves[1][0] && elves[1][1] >= elves[0][0]
|| elves[0][1] <= elves[1][0] && elves[1][1] <= elves[0][0] {
result += 1;
}
}
println!("{}", result);
}