From 1c71bd1ce1b77677c2768b791476888ab178f644 Mon Sep 17 00:00:00 2001 From: Valerie Date: Sat, 15 Apr 2023 15:51:30 -0400 Subject: [PATCH] created utility module for calculations needed by complex flags --- src/util.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/util.rs diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..d5cb60d --- /dev/null +++ b/src/util.rs @@ -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); +} +