From ab2992725246cfcdd88f2a6af6690153f374c335 Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Wed, 18 Aug 2021 14:52:17 -0500 Subject: [PATCH] switch from h,m,s captures to simple non-digit split --- src/main.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index ab7be1e..e3b2a5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,21 +20,31 @@ fn main() { let hms = Regex::new(r"(\d\d?)\|(\d\d)\|(\d\d)").unwrap(); let csv = Regex::new(r", ").unwrap(); + let dig = Regex::new(r"\D+").unwrap(); let parse_int = |m: Option| { m.unwrap().as_str().parse::().unwrap() }; +// let mut vec = +// hms.captures_iter(test) +// .map(|cap| +// cap.iter().skip(1) +// .map(parse_int) +// .collect::>() +// .chunks(3) +// .map(|c| (c[0],c[1],c[2])) +// .map(|(h,m,s)| h*3600 + m*60 +s) +// .sum()) +// .collect::>(); + let mut vec = - hms.captures_iter(test) - .map(|cap| - cap.iter().skip(1) - .map(parse_int) - .collect::>() - .chunks(3) - .map(|c| (c[0],c[1],c[2])) - .map(|(h,m,s)| h*3600 + m*60 +s) - .sum()) + dig.split(test) + .map(|c| c.parse::().unwrap()) + .collect::>() + .chunks(3) + .map(|c| (c[0],c[1],c[2])) + .map(|(h,m,s)| h*3600 + m*60 +s) .collect::>(); vec.sort_unstable();