Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::io::{BufReader};
- use std::io::prelude::*;
- use std::fs::File;
- fn fuel_need(weight:i32) -> i32{
- return weight / 3 - 2;
- }
- fn main() {
- let f = BufReader::new(File::open("data/input_1a.sdx").unwrap()); //This will crash if the file can't be found
- let mut modules : Vec<i32> = Vec::new();
- for line in f.lines() {
- modules.push(line.unwrap().parse::<i32>().unwrap())
- }
- let mut total : i32 = 0;
- for m in modules {
- let module_weight = fuel_need(m);
- total += module_weight;
- let mut fuel = module_weight;
- while fuel > 0 {
- fuel = fuel_need(fuel);
- if fuel > 0 {
- total += fuel;
- }
- }
- }
- println!("{}", total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement