diff options
-rw-r--r-- | 2019/rust/day01/src/main.rs | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/2019/rust/day01/src/main.rs b/2019/rust/day01/src/main.rs index c984e80..3eb12f7 100644 --- a/2019/rust/day01/src/main.rs +++ b/2019/rust/day01/src/main.rs @@ -2,29 +2,21 @@ use std::io::{self, BufRead}; fn read_input() -> Vec<i32> { let stdin = io::stdin(); - let nums: Vec<i32> = stdin.lock().lines().map(|x| x.unwrap().parse().unwrap()).collect(); - nums + stdin.lock().lines().map(|line| line.unwrap().parse().unwrap()).collect() } fn first_puzzle(payloads:&Vec<i32>) -> i32 { - let fuel = payloads.iter().fold(0, |fuel, mass| fuel + mass/3-2); - - fuel + payloads.iter().map(|mass| mass/3-2).sum() } fn second_puzzle(payloads:&Vec<i32>) -> i32 { fn fuel_required(mass:&i32) -> i32 { let fuel = mass/3-2; - if fuel > 0 { - fuel + fuel_required(&fuel) - } else { - 0 - } + if fuel > 0 { fuel + fuel_required(&fuel) } else { 0 } } - let fuel = payloads.iter().fold(0, |fuel, mass| fuel + fuel_required(mass)); - fuel + payloads.iter().map(|mass| fuel_required(mass)).sum() } fn main() { |