Skip to content

Commit

Permalink
[ceremonies/#75] replace find coprime below by n-1
Browse files Browse the repository at this point in the history
all n-1 are coprimes to n
  • Loading branch information
NicJak committed Nov 20, 2021
1 parent 635acd7 commit c9abcc0
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions ceremonies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,28 +523,11 @@ impl<T: Config> Module<T> {
}

fn find_coprime_below(upper_bound: u64) -> u64 {
for n in 1..(upper_bound) {
if Self::get_greatest_common_denominator(upper_bound, upper_bound - n) == 1 {
return upper_bound - n;
}
}
return 0;
}

fn get_greatest_common_denominator(a: u64, b: u64) -> u64 {
if a == 0 || b == 0 {
if upper_bound > 1 {
return upper_bound - 1;
} else {
return 0;
}

if a == b {
return a;
};

if a > b {
return Self::get_greatest_common_denominator(a - b, b);
}

return Self::get_greatest_common_denominator(a, b - a);
}

fn create_assignment_count(
Expand Down

0 comments on commit c9abcc0

Please sign in to comment.