day8: avoid having to manually define all the cmp traits
This commit is contained in:
20
src/day8.rs
20
src/day8.rs
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user