diff --git a/src/day03.rs b/src/day03.rs index 28b0cce..642b9f9 100644 --- a/src/day03.rs +++ b/src/day03.rs @@ -18,12 +18,12 @@ fn solve_task01(content: &str) -> i32 { let vector = utils::convert_to_string_slice(&content); vector.into_iter() - .map(|x| [&x[..x.len()/2], &x[x.len()/2..]] + .map(|x| [&x[..x.len()/2], &x[x.len()/2..]] // create package to compare .into_iter() - .map(|x| x.chars().collect::>()) - .reduce(|acc, x| &acc & &x).unwrap()) - .map(|x| *x.iter().next().unwrap()) - .map(|c| convert_char_to_prio(c) as i32) + .map(|x| x.chars().collect::>()) // remove duplicates per pack + .reduce(|acc, x| &acc & &x).unwrap()) // filter for only duplicates in all packages + .map(|x| *x.iter().next().unwrap()) // take first item in every set + .map(|c| convert_char_to_prio(c) as i32) // convert character to number .sum() }