From a68e7f0f03958fceb78c292056e85e77fe328302 Mon Sep 17 00:00:00 2001 From: Adrian Groh Date: Sat, 14 Dec 2024 12:33:10 +0100 Subject: [PATCH] Clean up parsing --- day13/src/main.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/day13/src/main.rs b/day13/src/main.rs index a438de3..c95d730 100644 --- a/day13/src/main.rs +++ b/day13/src/main.rs @@ -10,20 +10,27 @@ struct Machine { y3: isize, } -#[rustfmt::skip] fn parse(input: &str) -> Vec { let re = Regex::new(r"\d+").unwrap(); input .split("\n\n") .map(|m| { - let mut captures = re.captures_iter(m); + let &[x1, y1, x2, y2, x3, y3] = re + .captures_iter(m) + .take(6) + .map(|d| d.get(0).unwrap().as_str().parse().unwrap()) + .collect::>() + .as_slice() + else { + panic!() + }; Machine { - x1: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(), - y1: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(), - x2: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(), - y2: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(), - x3: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(), - y3: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(), + x1, + y1, + x2, + y2, + x3, + y3, } }) .collect()