2019 - day1 - part 2: beautily full
This commit is contained in:
parent
18d09765e2
commit
d9f9fb48ed
1 changed files with 14 additions and 9 deletions
|
@ -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() {
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue