day8: avoid having to manually define all the cmp traits

This commit is contained in:
2025-12-08 13:32:46 -08:00
parent 522e10a3ea
commit 3f9f7afd27

View File

@@ -138,28 +138,12 @@ fn part2(input: &Circuits) -> u64 {
panic!()
}
#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct JunctionPair {
d: u64,
a: usize,
b: usize,
d: u64,
}
impl Eq for JunctionPair {}
impl PartialEq for JunctionPair {
fn eq(&self, other: &Self) -> bool {
self.d == other.d
}
}
impl PartialOrd for JunctionPair {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.d.cmp(&other.d))
}
}
impl Ord for JunctionPair {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.d.cmp(&other.d)
}
}
fn make_heap(circuits: &Circuits) -> BinaryHeap<Reverse<JunctionPair>> {
BinaryHeap::from_iter(
circuits