use bitand for sets
This commit is contained in:
parent
ad309f5b33
commit
b4bf4e61ad
1 changed files with 2 additions and 2 deletions
|
@ -30,11 +30,11 @@ fn parse_input2(input: &str) -> Vec<u32> {
|
||||||
let mut out = Vec::with_capacity(input.len() / 3);
|
let mut out = Vec::with_capacity(input.len() / 3);
|
||||||
let lines: Vec<&str> = input.lines().collect();
|
let lines: Vec<&str> = input.lines().collect();
|
||||||
for group in lines.chunks_exact(3) {
|
for group in lines.chunks_exact(3) {
|
||||||
let [x, y, z] = group else {panic!()};
|
let [x, y, z] = group else { panic!() };
|
||||||
let x: HashSet<char> = HashSet::from_iter(x.chars());
|
let x: HashSet<char> = HashSet::from_iter(x.chars());
|
||||||
let y = HashSet::from_iter(y.chars());
|
let y = HashSet::from_iter(y.chars());
|
||||||
let z = HashSet::from_iter(z.chars());
|
let z = HashSet::from_iter(z.chars());
|
||||||
let xy: HashSet<char> = x.intersection(&y).copied().collect();
|
let xy = &x & &y;
|
||||||
let common = xy.intersection(&z).next().unwrap();
|
let common = xy.intersection(&z).next().unwrap();
|
||||||
out.push(get_priority(common));
|
out.push(get_priority(common));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue