diff --git a/.gitignore b/.gitignore index d9f5ff0..54bb07e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /target .idea +.fleet # Generated by Cargo # will have compiled files and executables debug/ diff --git a/src/prob1/mod.rs b/src/prob1/mod.rs index 21fe261..575654f 100644 --- a/src/prob1/mod.rs +++ b/src/prob1/mod.rs @@ -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::() { - 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::() { + accumulated += yay; + } else { + max = max.max(accumulated); + accumulated = 0; + } + }); max } diff --git a/src/prob5.rs b/src/prob5.rs index 8bb5be5..39a14cc 100644 --- a/src/prob5.rs +++ b/src/prob5.rs @@ -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 }