1
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 /target
.idea .idea
.fleet
# Generated by Cargo # Generated by Cargo
# will have compiled files and executables # will have compiled files and executables
debug/ debug/

View File

@ -1,13 +1,12 @@
use std::cmp::Reverse; use std::cmp::Reverse;
pub fn solve_part1(file_path: &str) -> i32 { 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 max = 0;
let mut accumulated = 0; let mut accumulated = 0;
lines.iter().for_each(|number| { 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>() { if let Ok(yay) = number.parse::<i32>() {
accumulated += yay; accumulated += yay;
} else { } else {

View File

@ -114,7 +114,7 @@ fn parser(content: &str) {
} }
pub fn solve(file_path: &str) -> i32 { 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); parser(&content);
0 0
} }