2019 - day1 - part 2: beautily full

This commit is contained in:
genofire 2020-09-07 21:36:04 +02:00
parent 18d09765e2
commit d9f9fb48ed

View file

@ -19,21 +19,25 @@ fn main() {
//all_modules.map(fuel_calc).sum() //all_modules.map(fuel_calc).sum()
//all_modules.map(fuel_calc).sum() //all_modules.map(fuel_calc).sum()
println!("Part2: I need {} fuel for all modules", all_modules.iter().fold(0, |sum, x | fuel_calc_with_fuel(*x) + sum )); println!("Part2: I need {} fuel for all modules", all_modules.iter().fold(0, |sum, x | fuel_tyranny(*x) + sum ));
} }
fn fuel_calc(mass: i32) -> i32 { fn fuel_calc(mass: i32) -> i32 {
mass / 3 - 2 mass / 3 - 2
} }
fn fuel_calc_with_fuel(mass: i32) -> i32 { fn fuel_tyranny(mass: i32) -> i32 {
let fuel = fuel_calc(mass); let fuel = fuel_calc(mass);
if fuel <= 0 { if fuel <= 0 {
return 0; return 0;
} }
fuel+fuel_calc_with_fuel(fuel) fuel+fuel_tyranny(fuel)
} }
#[cfg(test)]
mod tests {
use super::*;
#[test] #[test]
fn test_it() { fn test_it() {
assert_eq!(fuel_calc(12), 2); assert_eq!(fuel_calc(12), 2);
@ -41,3 +45,4 @@ fn test_it() {
assert_eq!(fuel_calc(1969), 654); assert_eq!(fuel_calc(1969), 654);
assert_eq!(fuel_calc(100756), 33583); assert_eq!(fuel_calc(100756), 33583);
} }
}