blob: 10d45ab9afbbce6d18ff02e11550a2062c72eb41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import gleam/io
pub fn main() {
io.debug(factorial(5))
io.debug(factorial(7))
}
// A recursive functions that calculates factorial
pub fn factorial(x: Int) -> Int {
case x {
// Base case
0 -> 1
1 -> 1
// Recursive case
_ -> x * factorial(x - 1)
}
}
|