Move day1 specific code to module, hide all outputs
This commit is contained in:
parent
25f30c89fb
commit
e067720cc8
2 changed files with 29 additions and 14 deletions
12
src/day1.rs
12
src/day1.rs
|
@ -1,3 +1,6 @@
|
|||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
|
||||
fn fuel_for(mass: u64) -> u64 {
|
||||
(mass / 3).saturating_sub(2)
|
||||
}
|
||||
|
@ -8,9 +11,16 @@ fn total_fuel(mass: u64) -> u64 {
|
|||
.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();
|
||||
println!("Fuel needed for bringing Santa home is: {}", total);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -1,25 +1,30 @@
|
|||
#[allow(dead_code)]
|
||||
mod day1;
|
||||
mod day2;
|
||||
mod day3;
|
||||
mod day4;
|
||||
mod day5;
|
||||
mod day6;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
fn main() -> std::io::Result<()> {
|
||||
println!("========================= DAY 6");
|
||||
day6::main()?;
|
||||
|
||||
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();
|
||||
day1::main(masses);
|
||||
//println!("========================= DAY 5");
|
||||
//day5::main()?;
|
||||
|
||||
day2::part_one();
|
||||
day2::part_two();
|
||||
//println!("========================= DAY 4");
|
||||
//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(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue