From 315f56f4c036d28241e3dfaf2c79884a23c40b41 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Sat, 3 Dec 2022 13:16:29 -0600 Subject: [PATCH] Day 3 part 2 --- three.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/three.rs b/three.rs index 7a0bed3..ebf2cd6 100644 --- a/three.rs +++ b/three.rs @@ -3,12 +3,12 @@ fn main() { let mut sum = 0u32; - for line in buf.split("\n") { - let (first, last) = line.split_at(line.len() / 2); - let mut seen_before = Vec::with_capacity(first.len()); + for chunk in buf.split("\n").collect::>().chunks_exact(3) { + let [line1, line2, line3] = chunk else { unreachable!() }; + let mut seen_before = Vec::with_capacity(line1.len()); - for c in first.chars() { - if last.contains(c) && !seen_before.contains(&c) { + for c in line1.chars() { + if !seen_before.contains(&c) && line2.contains(c) && line3.contains(c) { let priority = if c.is_ascii_uppercase() { (c as u8) - 65 + 27 } else {