From 19696f6388bed2f286609fd94aaaf813af4412d7 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Mon, 24 Jun 2024 21:53:10 +0200 Subject: [PATCH] minor change to day 1 --- lib/trebuchet/src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/trebuchet/src/lib.rs b/lib/trebuchet/src/lib.rs index 95de608..f85c82f 100644 --- a/lib/trebuchet/src/lib.rs +++ b/lib/trebuchet/src/lib.rs @@ -47,28 +47,25 @@ impl FromStr for CalibrationValue { // Get all number strings as numbers for (i, number_string) in NUMBER_STRINGS.iter().enumerate() { s.match_indices(number_string) - .for_each(|(index, _)| assorted.push((index, i))); + .for_each(|(index, _)| assorted.push((index, i.to_string()))); } // Extract all numeric characters - s.match_indices(char::is_numeric) - .try_for_each(|(index, number)| { - assorted.push((index, number.parse()?)); - Ok::<(), CalibrationError>(()) // Infer error type - })?; + s.match_indices(char::is_numeric).for_each(|(index, number)| { + assorted.push((index, number.to_string())); + }); // Sort by index assorted.sort_by_key(|(index, _)| *index); - // Remove indexes - let mut numbers = assorted.iter().map(|(_, number)| number); + let mut numbers = assorted.iter(); // Get first and last number let first = numbers.next().ok_or(CalibrationError::NoNumbers)?; let last = numbers.last().unwrap_or(first); // Format numbers - let number = format!("{first}{last}").parse()?; + let number = format!("{}{}", first.1, last.1).parse()?; Ok(Self { number }) }