remove all those unwraps and just index directly into the vector
This commit is contained in:
parent
c3a6c3d117
commit
c875ec5826
26
04/main.rs
26
04/main.rs
@ -32,16 +32,14 @@ fn part_one() {
|
||||
let mut overlaps = 0;
|
||||
for line in lines {
|
||||
if let Ok(ranges) = line {
|
||||
let v: Vec<Vec<i32>> = ranges
|
||||
let v: Vec<Vec<i8>> = ranges
|
||||
.split(",")
|
||||
.map(|r| r.split("-").map(|i| i.parse::<i32>().unwrap()).collect())
|
||||
.map(|r| r.split("-").map(|i| i.parse::<i8>().unwrap()).collect())
|
||||
.collect();
|
||||
// 00 ... 01
|
||||
// 10 ... 11
|
||||
if (v.get(0).unwrap().get(0) <= v.get(1).unwrap().get(0)
|
||||
&& v.get(0).unwrap().get(1) >= v.get(1).unwrap().get(1))
|
||||
|| (v.get(1).unwrap().get(0) <= v.get(0).unwrap().get(0)
|
||||
&& v.get(1).unwrap().get(1) >= v.get(0).unwrap().get(1))
|
||||
if (v[0][0] <= v[1][0] && v[0][1] >= v[1][1])
|
||||
|| (v[1][0] <= v[0][0] && v[1][1] >= v[0][1])
|
||||
{
|
||||
overlaps += 1;
|
||||
}
|
||||
@ -56,21 +54,17 @@ fn part_two() {
|
||||
let mut overlaps = 0;
|
||||
for line in lines {
|
||||
if let Ok(ranges) = line {
|
||||
let v: Vec<Vec<i32>> = ranges
|
||||
let v: Vec<Vec<i8>> = ranges
|
||||
.split(",")
|
||||
.map(|r| r.split("-").map(|i| i.parse::<i32>().unwrap()).collect())
|
||||
.map(|r| r.split("-").map(|i| i.parse::<i8>().unwrap()).collect())
|
||||
.collect();
|
||||
// 00 ... 01
|
||||
// 10 ... 11
|
||||
// uuuuuugh
|
||||
if (v.get(0).unwrap().get(0) <= v.get(1).unwrap().get(0)
|
||||
&& v.get(0).unwrap().get(1) >= v.get(1).unwrap().get(1))
|
||||
|| (v.get(1).unwrap().get(0) <= v.get(0).unwrap().get(0)
|
||||
&& v.get(1).unwrap().get(1) >= v.get(0).unwrap().get(1))
|
||||
|| (v.get(0).unwrap().get(0) <= v.get(1).unwrap().get(1)
|
||||
&& v.get(0).unwrap().get(0) >= v.get(1).unwrap().get(0))
|
||||
|| (v.get(0).unwrap().get(1) >= v.get(1).unwrap().get(0)
|
||||
&& v.get(0).unwrap().get(1) <= v.get(1).unwrap().get(1))
|
||||
if (v[0][0] <= v[1][0] && v[0][1] >= v[1][1])
|
||||
|| (v[1][0] <= v[0][0] && v[1][1] >= v[0][1])
|
||||
|| (v[0][0] <= v[1][1] && v[0][0] >= v[1][0])
|
||||
|| (v[0][1] >= v[1][0] && v[0][1] <= v[1][1])
|
||||
{
|
||||
overlaps += 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user