Skip to content

Commit

Permalink
Optimize 2024 day 23 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ictrobot committed Dec 23, 2024
1 parent bce98bd commit 067b67d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/year2024/src/day23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,28 @@ impl Day23 {
#[must_use]
pub fn part1(&self) -> u32 {
let mut count = 0;
for n1 in 0..self.nodes.len() {

// 19 = b't' - b'a'
for n1 in 19 * 26..20 * 26 {
for n2 in self.neighbors(n1) {
if n2 > n1 {
break;
// Ensure the combination is only counted once if the second node also starts with t
if n2 / 26 == 19 && n2 >= n1 {
continue;
}

for n3 in Self::iter(Self::intersect(self.nodes[n1], self.nodes[n2])) {
if n3 > n2 {
if n3 >= n2 {
break;
}

// 19 = b't' - b'a'
if n1 / 26 == 19 || n2 / 26 == 19 || n3 / 26 == 19 {
count += 1;
if n3 / 26 == 19 && n3 >= n1 {
continue;
}

count += 1;
}
}
}

count
}

Expand Down

0 comments on commit 067b67d

Please sign in to comment.