Cleaned up a bit
This commit is contained in:
parent
f1250271ea
commit
5118d766b3
|
@ -6,47 +6,32 @@ fn main() {
|
||||||
println!("Part 2: {}", part2(&input));
|
println!("Part 2: {}", part2(&input));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part1(input: &str) -> i32 {
|
fn nums(input: &str) -> Vec<i32> {
|
||||||
let mut r = 0;
|
input
|
||||||
for l in input.lines() {
|
.replace(",", "-")
|
||||||
let mut c = l.split(",");
|
.split("-")
|
||||||
let p1 = c.next().unwrap();
|
.map(|s| s.parse::<i32>().unwrap())
|
||||||
let p2 = c.next().unwrap();
|
.collect()
|
||||||
let mut p1c = p1.split("-");
|
}
|
||||||
let p1n1 = p1c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
let p1n2 = p1c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
let mut p2c = p2.split("-");
|
|
||||||
let p2n1 = p2c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
let p2n2 = p2c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
|
|
||||||
if (p1n1 <= p2n1 && p1n2 >= p2n2) || (p2n1 <= p1n1 && p2n2 >= p1n2) {
|
fn part1(input: &str) -> i32 {
|
||||||
r += 1
|
input
|
||||||
}
|
.lines()
|
||||||
}
|
.map(|l| {
|
||||||
r
|
let n = nums(l);
|
||||||
|
((n[0] <= n[2] && n[1] >= n[3]) || (n[2] <= n[0] && n[3] >= n[1])) as i32
|
||||||
|
})
|
||||||
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(input: &str) -> i32 {
|
fn part2(input: &str) -> i32 {
|
||||||
let mut r = 0;
|
input
|
||||||
for l in input.lines() {
|
.lines()
|
||||||
println!("{}", l);
|
.map(|l| {
|
||||||
let mut c = l.split(",");
|
let n = nums(l);
|
||||||
let p1 = c.next().unwrap();
|
(n[0] <= n[3] && n[2] <= n[1]) as i32
|
||||||
let p2 = c.next().unwrap();
|
})
|
||||||
let mut p1c = p1.split("-");
|
.sum()
|
||||||
let x1 = p1c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
let x2 = p1c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
let mut p2c = p2.split("-");
|
|
||||||
let y1 = p2c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
let y2 = p2c.next().unwrap().parse::<i32>().unwrap();
|
|
||||||
|
|
||||||
println!("{}-{} , {}-{}", x1, x2, y1, y2);
|
|
||||||
if x1 <= y2 && y1 <= x2 {
|
|
||||||
r += 1;
|
|
||||||
println!("overlap");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue