Private Leaderboard: join 265794-f7a74408 https://adventofcode.com/2019/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
674 B

fn fuel_for_mass1(mass: u64) -> u64 {
mass / 3 - 2
}
fn fuel_for_modules1<I>(input: I) -> u64
where
I: IntoIterator<Item = u64>,
{
input.into_iter().map(fuel_for_mass1).sum()
}
fn fuel_for_mass2(mass: u64) -> u64 {
if mass <= 8 { return 0; } /* wish really hard */
let fuel = mass / 3 - 2;
fuel + fuel_for_mass2(fuel)
}
fn fuel_for_modules2<I>(input: I) -> u64
where
I: IntoIterator<Item = u64>,
{
input.into_iter().map(fuel_for_mass2).sum()
}
fn main() {
let input = include_str!("input.txt").split_whitespace().map(|s| s.parse::<u64>().unwrap());
println!("Fuel 1: {}", fuel_for_modules1(input.clone()));
println!("Fuel 2: {}", fuel_for_modules2(input));
}