Skip to content

Commit f31bb6b

Browse files
committed
Sort t's to front
1 parent a8902c0 commit f31bb6b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/day23.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::str;
2+
use std::cmp::Ordering;
23

34
use aoc_runner_derive::aoc;
45
use bitvec::array::BitArray;
@@ -103,7 +104,17 @@ pub fn part2(s: &str) -> &'static str {
103104
}
104105
}
105106

106-
vertecies.sort_unstable_by(|a, b| b.1.cmp(&a.1));
107+
vertecies.sort_unstable_by(|a, b| {
108+
if (a.0 / 26) as u8 + b'a' == b't' && (b.0 / 26) as u8 + b'a' == b't' {
109+
b.1.cmp(&a.1)
110+
} else if (a.0 / 26) as u8 + b'a' == b't' {
111+
Ordering::Less
112+
} else if (b.0 / 26) as u8 + b'a' == b't' {
113+
Ordering::Greater
114+
} else {
115+
b.1.cmp(&a.1)
116+
}
117+
});
107118
let mut i = vertecies.len() - 1;
108119
while vertecies[i].1 == 0 {
109120
i -= 1;
@@ -141,7 +152,6 @@ pub fn part2(s: &str) -> &'static str {
141152
}
142153
}
143154

144-
// Using this algorithm: https://web.archive.org/web/20160911054636/http://www.dcs.gla.ac.uk/~pat/jchoco/clique/indSetMachrahanish/papers/tomita2003.pdf
145155
fn expand(
146156
mut r: &mut [(u16, u16)],
147157
g: &BitArray<[u64; BAL]>,

0 commit comments

Comments
 (0)