1
0

More rust-ish way of doing things.

This commit is contained in:
Pcornat 2022-12-04 13:27:27 +01:00
parent 07b0bf7558
commit 2551a5fa4c
2 changed files with 5 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
.idea

View File

@ -40,10 +40,7 @@ impl From<char> for Play {
'X' => Play::Rock, 'X' => Play::Rock,
'Y' => Play::Paper, 'Y' => Play::Paper,
'Z' => Play::Scissors, 'Z' => Play::Scissors,
other => panic!( other => panic!("Only A, B, C, X, Y or Z letters are available. Had {other}"),
"Only A, B, C, X, Y or Z letters are available. Had {}",
other
),
} }
} }
} }
@ -107,8 +104,9 @@ pub fn solve_part1(file_path: &str) -> i32 {
lines lines
.iter() .iter()
.map(|line| { .map(|line| {
let first: char = line.chars().nth(0).unwrap_or('R'); let mut line_iter = line.chars();
let last: char = line.chars().nth(2).unwrap_or('R'); let first: char = line_iter.next().unwrap_or('R');
let last: char = line_iter.last().unwrap_or('R');
round_score(first, last) round_score(first, last)
}) })
.collect::<Vec<i32>>() .collect::<Vec<i32>>()