diff options
Diffstat (limited to 'aoc-2020-gleam/src/ext/intx.gleam')
-rw-r--r-- | aoc-2020-gleam/src/ext/intx.gleam | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/aoc-2020-gleam/src/ext/intx.gleam b/aoc-2020-gleam/src/ext/intx.gleam index 9f06850..077b4f2 100644 --- a/aoc-2020-gleam/src/ext/intx.gleam +++ b/aoc-2020-gleam/src/ext/intx.gleam @@ -1,3 +1,24 @@ +import gleam/int +import gleam/order.{Eq, Gt, Lt} + pub fn is_between(number: Int, min: Int, and max: Int) { min <= number && number <= max } + +pub fn ceil_divide(dividend: Int, by divisor: Int) -> Int { + { dividend + divisor - 1 } / divisor +} + +fn gcd(a: Int, b: Int) -> Int { + case b == 0 { + True -> a + False -> gcd(b, a % b) + } +} + +pub fn lcm(a: Int, b: Int) -> Int { + case int.compare(a, b) { + Gt | Eq -> { a / gcd(a, b) } * b + Lt -> { b / gcd(a, b) } * a + } +} |