simplify priority math

This commit is contained in:
David 2022-12-03 09:36:44 -05:00
parent 894ddd8ca7
commit fc2099c14c

View File

@ -43,11 +43,7 @@ fn part_one() {
}
for item in pocket_two.chars() {
if knapsack.contains_key(&item) {
if item as u32 > 96 {
priorities += item as u32 - 96
} else {
priorities += item as u32 - 38
}
priorities += (item as u32 - 38) % 58;
break;
}
}
@ -78,12 +74,8 @@ fn part_two() {
HashSet::from_iter(one.intersection(three));
let mut result = intermediate_one.intersection(&intermediate_two);
if let Some(item) = result.next() {
// double pointers!
if **item as u32 > 96 {
priorities += **item as u32 - 96
} else {
priorities += **item as u32 - 38
}
// double pointer!
priorities += (**item as u32 - 38) % 58;
}
}
group.clear();