2019 - day1 - part 2: use ref instatt pointer

This commit is contained in:
genofire 2020-09-07 21:39:42 +02:00
parent d9f9fb48ed
commit 8a201e8aa0

View file

@ -12,14 +12,14 @@ fn main() {
]; ];
let mut result = 0; let mut result = 0;
for i in all_modules.iter() { for &i in all_modules.iter() {
result += fuel_calc(*i); result += fuel_calc(i);
} }
println!("Part1: I need {} fuel for all modules", result); println!("Part1: I need {} fuel for all modules", result);
//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_tyranny(*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 {