Skip to content

Commit

Permalink
Minor simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 20, 2023
1 parent d5212fc commit a07a091
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions rs/src/day20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn part1(data: &str) -> Option<u32> {
.collect::<HashMap<_, _>>();
let (mut x, mut y) = (0, 0);
for _ in 0..1000 {
let mut queue: VecDeque<_> = [("button", "broadcaster", false)].into();
let mut queue = VecDeque::from([("button", "broadcaster", false)]);
while let Some((src, key, value)) = queue.pop_front() {
if value {
x += 1;
Expand Down Expand Up @@ -161,15 +161,11 @@ pub fn part2(data: &str) -> Option<usize> {
.collect::<Vec<_>>();
snapshot.sort_by(|(a, _), (b, _)| a.cmp(b));
let i = seen.len();
match seen.entry(snapshot) {
std::collections::hash_map::Entry::Occupied(entry) => {
break Some(i - *entry.get());
}
std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(i);
}
let j = *seen.entry(snapshot).or_insert(i);
if i != j {
break i - j;
}
let mut queue: VecDeque<_> = [("button", "broadcaster", false)].into();
let mut queue = VecDeque::from([("button", "broadcaster", false)]);
while let Some((src, key, value)) = queue.pop_front() {
let Some(value) = (match state.get_mut(key) {
Some(state) => state.pulse(src, value),
Expand All @@ -182,7 +178,7 @@ pub fn part2(data: &str) -> Option<usize> {
};
queue.extend(dsts.intersection(&subset).map(|&dst| (key, dst, value)));
}
}?;
};
Some(lcm(acc, size))
})
}
Expand Down

0 comments on commit a07a091

Please sign in to comment.