created utility module for calculations needed by complex flags
This commit is contained in:
parent
cadb1949a7
commit
1c71bd1ce1
1 changed files with 15 additions and 0 deletions
15
src/util.rs
Normal file
15
src/util.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
pub fn gcd(a: usize, b: usize) -> usize {
|
||||
if a == 0 || b == 0 { return 0; }
|
||||
let min = usize::min(a, b);
|
||||
let max = usize::max(a, b);
|
||||
|
||||
let remainder = max % min;
|
||||
if remainder == 0 { return min; }
|
||||
else { return gcd(min, remainder); }
|
||||
}
|
||||
|
||||
pub fn lcm(a: usize, b: usize) -> usize {
|
||||
return ( a * b ) / gcd(a, b);
|
||||
}
|
||||
|
Loading…
Reference in a new issue