From 0d7097dbf84b619dd9657a5f86afba00af2a5928 Mon Sep 17 00:00:00 2001 From: Florent DENEF Date: Fri, 2 Dec 2022 16:06:00 +0100 Subject: [PATCH] WAiting for approval of this function. --- src/prob2/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/prob2/mod.rs b/src/prob2/mod.rs index 3defb55..d938ce7 100644 --- a/src/prob2/mod.rs +++ b/src/prob2/mod.rs @@ -74,3 +74,19 @@ pub fn round_score(play: char, counter_play: char) -> 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(); + lines + .iter() + .map(|line| { + let first: char = line.chars().nth(0).unwrap_or('R'); + let last: char = line.chars().nth(2).unwrap_or('R'); + round_score(first, last) + }) + .collect::>() + .iter() + .sum() +}