use std::io::{self, BufRead}; fn read_input() -> Vec { let stdin = io::stdin(); stdin.lock().lines().map(|line| line.unwrap().parse().unwrap()).collect() } fn first_puzzle(payloads:&Vec) -> i32 { payloads.iter().map(|mass| mass/3-2).sum() } fn second_puzzle(payloads:&Vec) -> i32 { fn fuel_required(mass:&i32) -> i32 { let fuel = mass/3-2; if fuel > 0 { fuel + fuel_required(&fuel) } else { 0 } } payloads.iter().map(|mass| fuel_required(mass)).sum() } fn main() { let payloads = read_input(); let first = first_puzzle(&payloads); println!("first: {}", first); let second = second_puzzle(&payloads); println!("second: {}", second); }