2019: day01: improve sub overflow handling

This commit is contained in:
Antoine Martin 2019-12-01 16:36:46 +01:00
parent 5e2fb25c94
commit dd4e610324

View file

@ -10,10 +10,7 @@ pub fn run() -> Result<()> {
} }
fn fuel_needed(module_weight: u64) -> u64 { fn fuel_needed(module_weight: u64) -> u64 {
match (module_weight / 3).checked_sub(2) { (module_weight / 3).saturating_sub(2)
Some(f) => f,
None => 0,
}
} }
fn part1(input: &str) -> Result<u64> { fn part1(input: &str) -> Result<u64> {