diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-12-24 14:20:16 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-12-24 14:20:16 -0500 |
| commit | 9e0017e86ed28ccc2f855807f387a1e451260d85 (patch) | |
| tree | 7fe1b0b931dc82777d8b471e95147eb1edfda184 /docs/integers.md | |
| parent | f4b105456ad5f0949800d19acdb3403de26d7678 (diff) | |
Add Int:factorial() and n:choose(k)
Diffstat (limited to 'docs/integers.md')
| -rw-r--r-- | docs/integers.md | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/docs/integers.md b/docs/integers.md index fe1fbc0c..b69ed2b9 100644 --- a/docs/integers.md +++ b/docs/integers.md @@ -122,6 +122,60 @@ Each integer type has its own version of the following functions. Functions can be called either on the type itself: `Int.sqrt(x)` or as a method call: `x:sqrt()`. Method call syntax is preferred. +### `choose` + +**Description:** +Computes the binomial coefficient of the given numbers (the equivalent of `n` +choose `k` in combinatorics). This is equal to `n:factorial()/(k:factorial() * +(n-k):factorial())`. + +**Signature:** +```tomo +func choose(n: Int, k: Int -> Int) +``` + +**Parameters:** + +- `n`: The number of things to choose from. +- `k`: The number of things to be chosen. + +**Returns:** +The binomial coefficient, equivalent to the number of ways to uniquely choose +`k` objects from among `n` objects, ignoring order. + +**Example:** +```tomo +>> 4:choose(2) += 6 +``` + +--- + +### `factorial` + +**Description:** +Computes the factorial of an integer. + +**Signature:** +```tomo +func factorial(n: Int -> Text) +``` + +**Parameters:** + +- `n`: The integer to compute the factorial of. + +**Returns:** +The factorial of the given integer. + +**Example:** +```tomo +>> 10:factorial() += 3628800 +``` + +--- + ### `format` **Description:** |
