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