Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ziegfried committed Dec 15, 2023
1 parent 4cc9541 commit 014eeeb
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions 2023/day15/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn test_part1() {

#[derive(Debug)]
enum Op {
Remove,
Add,
Remove,
}

fn part2(input: &Input) -> Result {
Expand All @@ -50,23 +50,20 @@ fn part2(input: &Input) -> Result {
};
let h = hash(label.as_str());
match op {
Op::Remove => {
boxes[h] = boxes[h]
.iter()
.filter(|(l, _)| l != &label)
.cloned()
.collect::<Vec<_>>();
}
Op::Add => {
if let Some(idx) = boxes[h].iter().position(|(l, _)| l == &label) {
boxes[h][idx] = (label.clone(), focal_len);
} else {
boxes[h].push((label.clone(), focal_len));
}
}
Op::Remove => {
if let Some(idx) = boxes[h].iter().position(|(l, _)| l == &label) {
boxes[h].remove(idx);
}
}
}
}

boxes
.iter()
.enumerate()
Expand Down

0 comments on commit 014eeeb

Please sign in to comment.