This commit is contained in:
Stefan Schwarz 2020-04-19 01:56:59 +02:00
commit 1df50835be
7 changed files with 251 additions and 0 deletions

24
src/day1/main.rs Normal file
View file

@ -0,0 +1,24 @@
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::<i64>().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
}