From 76e1d24c9cb3f2461f4dca08271fa25f97e820b7 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Thu, 6 Apr 2023 22:00:05 +0200 Subject: Finish day 13 --- aoc-2020-gleam/src/ext/intx.gleam | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'aoc-2020-gleam/src/ext') 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 + } +} -- cgit v1.2.3