Much cleaner loop for p2
This commit is contained in:
parent
18915dfd8a
commit
7663397c1b
1 changed files with 8 additions and 14 deletions
|
@ -60,22 +60,16 @@ fn part2(lines: &[String]) {
|
|||
|
||||
let mut sum: u32 = 0;
|
||||
for chunk in lines.chunks(GROUP_SIZE) {
|
||||
let mut outlier: Option<char> = None;
|
||||
'outlier_search: for i in 0..GROUP_SIZE {
|
||||
if i != GROUP_SIZE - 1 {
|
||||
for i in 0..GROUP_SIZE - 1 {
|
||||
sets[i].clear();
|
||||
chunk[i].chars().collect_into(&mut sets[i]);
|
||||
} else {
|
||||
for c in chunk[i].chars() {
|
||||
if sets[0..GROUP_SIZE - 1].into_iter().all(|s| s.contains(&c)) {
|
||||
outlier = Some(c);
|
||||
break 'outlier_search;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let outlier = outlier.expect("Expect at least one outlier");
|
||||
let outlier = chunk[GROUP_SIZE - 1]
|
||||
.chars()
|
||||
.find(|c| sets[0..GROUP_SIZE - 1].into_iter().all(|s| s.contains(&c)))
|
||||
.expect("Expect at least one outlier");
|
||||
|
||||
let priority = to_priority(outlier).unwrap();
|
||||
dbg!(outlier, priority);
|
||||
sum += priority;
|
||||
|
|
Loading…
Reference in a new issue