From 2551a5fa4ca178f8f1d8d1198bb1094fc1dcdf85 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Sun, 4 Dec 2022 13:27:27 +0100 Subject: [PATCH] More rust-ish way of doing things. --- .gitignore | 1 + src/prob2/mod.rs | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..2a0038a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.idea \ No newline at end of file diff --git a/src/prob2/mod.rs b/src/prob2/mod.rs index 1646b0f..c960b2a 100644 --- a/src/prob2/mod.rs +++ b/src/prob2/mod.rs @@ -40,10 +40,7 @@ impl From 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::>()