How to make "combinations" (Math)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Konrad

How to make combinations and permutations?

C = ( (n +r -1)! ) / r! * (n - 1)!
or C = n! / (n - 1)

In gdscript there is no operator " ! "

Maybe there is an operator similar to “!”? It would help me.

Konrad | 2021-01-07 18:41

:bust_in_silhouette: Reply From: poetastrophe

You would use a loop and a method. I am only writing some pseudocode to get you along:

def factorial(n):
    int product = 1
    for int i = 1; i<n+1; ++i:
        product = product*i
    return product

then you don’t need the ! operator. For example writing n!/(n-1) = factorial(n)/(n-1)