aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/ext/intx.gleam
blob: 077b4f2a7634f8842a9dc389db2f7947fd59043d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
  }
}