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:
parent
e3ecc0429f
commit
1d7a4b95a4
2 changed files with 29 additions and 3 deletions
|
@ -30,7 +30,12 @@ pub fn part1() -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part2() -> 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)]
|
#[cfg(test)]
|
||||||
|
@ -55,4 +60,9 @@ mod tests {
|
||||||
fn test_part1() {
|
fn test_part1() {
|
||||||
assert_eq!(part1(), 3226488)
|
assert_eq!(part1(), 3226488)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_part2() {
|
||||||
|
assert_eq!(part2(), 4836845)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,24 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
mod day1;
|
mod day1;
|
||||||
|
mod day2;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let res1 = day1::part1();
|
let args: Vec<String> = env::args().collect();
|
||||||
let res2 = day1::part2();
|
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: {}", res1);
|
||||||
println!("part 1: {}", res2);
|
println!("part 1: {}", res2);
|
||||||
|
|
Loading…
Reference in a new issue