Move day1 specific code to module, hide all outputs

This commit is contained in:
Vladan Popovic 2019-12-24 21:27:45 +01:00
parent 25f30c89fb
commit e067720cc8
2 changed files with 29 additions and 14 deletions

View file

@ -1,3 +1,6 @@
use std::fs::File;
use std::io::{self, BufRead, BufReader};
fn fuel_for(mass: u64) -> u64 { fn fuel_for(mass: u64) -> u64 {
(mass / 3).saturating_sub(2) (mass / 3).saturating_sub(2)
} }
@ -8,9 +11,16 @@ fn total_fuel(mass: u64) -> u64 {
.sum() .sum()
} }
pub fn main(masses: Vec<u64>) { pub fn main() -> io::Result<()> {
let f = BufReader::new(File::open("day1-input.txt")?);
let masses: Vec<u64> = f
.lines()
.map(|line| line.unwrap().parse().unwrap())
.collect();
let total: u64 = masses.into_iter().map(total_fuel).sum(); let total: u64 = masses.into_iter().map(total_fuel).sum();
println!("Fuel needed for bringing Santa home is: {}", total); println!("Fuel needed for bringing Santa home is: {}", total);
Ok(())
} }
#[test] #[test]

View file

@ -1,25 +1,30 @@
#[allow(dead_code)]
mod day1; mod day1;
mod day2; mod day2;
mod day3; mod day3;
mod day4; mod day4;
mod day5;
mod day6;
use std::fs::File; fn main() -> std::io::Result<()> {
use std::io::{self, BufRead, BufReader}; println!("========================= DAY 6");
day6::main()?;
fn main() -> io::Result<()> { //println!("========================= DAY 5");
let f = BufReader::new(File::open("day1-input.txt")?); //day5::main()?;
let masses: Vec<u64> = f
.lines()
.map(|line| line.unwrap().parse().unwrap())
.collect();
day1::main(masses);
day2::part_one(); //println!("========================= DAY 4");
day2::part_two(); //day4::main()?;
day3::main()?; //println!("========================= DAY 3");
//day3::main()?;
day4::main()?; //println!("========================= DAY 2");
//day2::part_one();
//day2::part_two();
//println!("========================= DAY 1");
//day1::main()?;
Ok(()) Ok(())
} }