More rust-ish way of doing things.
This commit is contained in:
parent
07b0bf7558
commit
2551a5fa4c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target
|
||||
.idea
|
@ -40,10 +40,7 @@ impl From<char> for Play {
|
||||
'X' => Play::Rock,
|
||||
'Y' => Play::Paper,
|
||||
'Z' => Play::Scissors,
|
||||
other => panic!(
|
||||
"Only A, B, C, X, Y or Z letters are available. Had {}",
|
||||
other
|
||||
),
|
||||
other => panic!("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
|
||||
.iter()
|
||||
.map(|line| {
|
||||
let first: char = line.chars().nth(0).unwrap_or('R');
|
||||
let last: char = line.chars().nth(2).unwrap_or('R');
|
||||
let mut line_iter = line.chars();
|
||||
let first: char = line_iter.next().unwrap_or('R');
|
||||
let last: char = line_iter.last().unwrap_or('R');
|
||||
round_score(first, last)
|
||||
})
|
||||
.collect::<Vec<i32>>()
|
||||
|
Loading…
Reference in New Issue
Block a user