created utility module for calculations needed by complex flags

This commit is contained in:
Valerie Wolfe 2023-04-15 15:51:30 -04:00
parent cadb1949a7
commit 1c71bd1ce1

15
src/util.rs Normal file
View 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);
}