Mojo function
perm
perm(n: Int, k: Int = -1) -> Int
Computes the number of ways to arrange k items from n items without repetition (permutations).
Equivalent to Python's math.perm(n, k).
Examples:
from std.math import perm
print(perm(5, 2)) # 20
print(perm(5)) # 120 (same as factorial(5))
print(perm(5, 0)) # 1Args:
- n (
Int): The total number of items. Must be non-negative. - k (
Int): The number of items to arrange. Must be non-negative and at mostn. If omitted (default), returnsn!viafactorial(n).
Returns:
Int: The number of permutations P(n, k) = n! / (n-k)!. Asserts if n is
negative, k is negative, or k > n.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!