1
0
Fork 0
This commit is contained in:
Pcornat 2022-12-26 13:52:23 +01:00
parent 6245e1a17c
commit 066a5894d3
3 changed files with 13 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
/target
.idea
.fleet
# Generated by Cargo
# will have compiled files and executables
debug/

View File

@ -1,20 +1,19 @@
use std::cmp::Reverse;
pub fn solve_part1(file_path: &str) -> i32 {
let contents =
std::fs::read_to_string(file_path).expect("Please provide a text file as an argument.");
let lines: Vec<&str> = contents.split('\n').collect();
let mut max = 0;
let mut accumulated = 0;
lines.iter().for_each(|number| {
if let Ok(yay) = number.parse::<i32>() {
accumulated += yay;
} else {
max = max.max(accumulated);
accumulated = 0;
}
});
std::fs::read_to_string(file_path)
.unwrap_or_else(|err| panic!("Please provide a text file as an argument: {err}"))
.lines()
.for_each(|number| {
if let Ok(yay) = number.parse::<i32>() {
accumulated += yay;
} else {
max = max.max(accumulated);
accumulated = 0;
}
});
max
}

View File

@ -114,7 +114,7 @@ fn parser(content: &str) {
}
pub fn solve(file_path: &str) -> i32 {
let content = std::fs::read_to_string(file_path).expect("Please provide a file.");
let content = std::fs::read_to_string(file_path).unwrap_or_else(|err| panic!("{err}"));
parser(&content);
0
}