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,25 +19,30 @@ fn main() {
//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 {
mass / 3 - 2
}
fn fuel_calc_with_fuel(mass: i32) -> i32 {
fn fuel_tyranny(mass: i32) -> i32 {
let fuel = fuel_calc(mass);
if fuel <= 0 {
return 0;
}
fuel+fuel_calc_with_fuel(fuel)
fuel+fuel_tyranny(fuel)
}
#[test]
fn test_it() {
assert_eq!(fuel_calc(12), 2);
assert_eq!(fuel_calc(14), 2);
assert_eq!(fuel_calc(1969), 654);
assert_eq!(fuel_calc(100756), 33583);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_it() {
assert_eq!(fuel_calc(12), 2);
assert_eq!(fuel_calc(14), 2);
assert_eq!(fuel_calc(1969), 654);
assert_eq!(fuel_calc(100756), 33583);
}
}