Day 3, puzzle 2
This commit is contained in:
parent
adb8cfd91a
commit
879c2c411c
17
src/bin/d3p2.rs
Normal file
17
src/bin/d3p2.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use aoc22::day3;
|
||||
use aoc22::util;
|
||||
|
||||
pub fn main() {
|
||||
let rucksacks = day3::parse_rucksacks(&util::parse_input());
|
||||
|
||||
let mut sum = 0;
|
||||
for group in rucksacks.chunks_exact(3) {
|
||||
// Intersection of the unions of each rucksack's compartments
|
||||
let common = &(&(&group[0].0 | &group[0].1) & &(&group[1].0 | &group[1].1))
|
||||
& &(&group[2].0 | &group[2].1);
|
||||
assert!(common.len() == 1);
|
||||
sum += day3::priority(*common.iter().next().unwrap());
|
||||
}
|
||||
|
||||
println!("Sum of priorities is {}", sum);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user