1
0
Fork 0
mirror of https://github.com/Findus23/AdventOfCode2019.git synced 2024-08-27 19:52:12 +02:00

finish 1 in rust

This commit is contained in:
Lukas Winkler 2019-12-05 11:54:37 +01:00
parent e3ecc0429f
commit 1d7a4b95a4
Signed by: lukas
GPG key ID: 54DE4D798D244853
2 changed files with 29 additions and 3 deletions

View file

@ -30,7 +30,12 @@ pub fn part1() -> i32 {
}
pub fn part2() -> i32 {
return 1;
let data = fs::read_to_string("../python/1/input.txt").expect("Unable to read file");
let ints = data
.lines()
.map(|line| advanced_fuel(line.parse().expect("error when parsing line as integer")))
.sum();
return ints;
}
#[cfg(test)]
@ -55,4 +60,9 @@ mod tests {
fn test_part1() {
assert_eq!(part1(), 3226488)
}
#[test]
fn test_part2() {
assert_eq!(part2(), 4836845)
}
}

View file

@ -1,8 +1,24 @@
use std::env;
mod day1;
mod day2;
fn main() {
let res1 = day1::part1();
let res2 = day1::part2();
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
println!("specify day");
std::process::exit(1);
}
let res1 = match args[1].as_str() {
"1" => day1::part1(),
"2" => day2::part1(),
_ => -1,
};
let res2 = match args[1].as_str() {
"1" => day1::part2(),
"2" => day2::part2(),
_ => -1,
};
println!("part 1: {}", res1);
println!("part 1: {}", res2);