Update.
This commit is contained in:
parent
6245e1a17c
commit
066a5894d3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
/target
|
||||
.idea
|
||||
.fleet
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user