use std::io::{self, BufRead}; fn main() -> io::Result<()> { let mut total: i64 = 0; io::stdin() .lock() .lines() .filter_map(|l| l.ok()) .filter_map(|l| l.parse::().ok()) .for_each(|line| { let mut cost = fuel_cost(line); while cost > 0 { total += cost; cost = fuel_cost(cost); } }); println!("total fuel needed: {}", total); Ok(()) } fn fuel_cost(mass: i64) -> i64 { mass / 3 - 2 }