Day 3 part 2
This commit is contained in:
parent
8dea79ddd6
commit
315f56f4c0
10
three.rs
10
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::<Vec<_>>().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 {
|
||||
|
|
Loading…
Reference in a new issue