1
0

WAiting for approval of this function.

This commit is contained in:
Florent DENEF 2022-12-02 16:06:00 +01:00
parent c90d69fdb9
commit 0d7097dbf8

View File

@ -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::<Vec<i32>>()
.iter()
.sum()
}