diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-02 00:54:47 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-02 00:54:47 -0500 |
commit | 41abfa051d6b24702c64c96cd9ab24fff700d819 (patch) | |
tree | bb276b045ee5840cff9de9272ca61cf903e52da7 | |
parent | 4f3b840dd2d857a73a58e266cf317629f2f90d4e (diff) | |
download | advent-of-code-41abfa051d6b24702c64c96cd9ab24fff700d819.tar.gz advent-of-code-41abfa051d6b24702c64c96cd9ab24fff700d819.zip |
no reason for these unwraps
-rw-r--r-- | src/2021/1/mod.rs | 6 | ||||
-rw-r--r-- | src/2021/2/mod.rs | 12 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/2021/1/mod.rs b/src/2021/1/mod.rs index fc474cb..045e492 100644 --- a/src/2021/1/mod.rs +++ b/src/2021/1/mod.rs @@ -4,8 +4,7 @@ pub fn part1() -> anyhow::Result<i64> { .map(|a| a[1] - a[0]) .filter(|x| *x > 0) .count() - .try_into() - .unwrap()) + .try_into()?) } pub fn part2() -> anyhow::Result<i64> { @@ -17,6 +16,5 @@ pub fn part2() -> anyhow::Result<i64> { .map(|a| a[1] - a[0]) .filter(|x| *x > 0) .count() - .try_into() - .unwrap()) + .try_into()?) } diff --git a/src/2021/2/mod.rs b/src/2021/2/mod.rs index 28a4caf..ec89d21 100644 --- a/src/2021/2/mod.rs +++ b/src/2021/2/mod.rs @@ -4,11 +4,11 @@ pub fn part1() -> anyhow::Result<i64> { for line in data_lines!()? { let line = line?; if let Some(n) = line.strip_prefix("forward ") { - horizontal += n.parse::<i64>().unwrap(); + horizontal += n.parse::<i64>()?; } else if let Some(n) = line.strip_prefix("down ") { - vertical += n.parse::<i64>().unwrap(); + vertical += n.parse::<i64>()?; } else if let Some(n) = line.strip_prefix("up ") { - vertical -= n.parse::<i64>().unwrap(); + vertical -= n.parse::<i64>()?; } } Ok(horizontal * vertical) @@ -21,13 +21,13 @@ pub fn part2() -> anyhow::Result<i64> { for line in data_lines!()? { let line = line?; if let Some(n) = line.strip_prefix("forward ") { - let x = n.parse::<i64>().unwrap(); + let x = n.parse::<i64>()?; horizontal += x; vertical += aim * x; } else if let Some(n) = line.strip_prefix("down ") { - aim += n.parse::<i64>().unwrap(); + aim += n.parse::<i64>()?; } else if let Some(n) = line.strip_prefix("up ") { - aim -= n.parse::<i64>().unwrap(); + aim -= n.parse::<i64>()?; } } Ok(horizontal * vertical) |