package ints;
class Combinatory{
public static int varNoRep(int n,int m){
if ((n >= m)&&(m >= 0)){
int out = 1;
for (;m > 0;m--,n--)
out *= n;
return out;
} else return -1;
}
public static int varRep(int n,int m){
if ((n >= m)&&(m >= 0)){
int out = 1;
for (;m > 0;m--)
out *= n;
return out;
} else return -1;
}
public static int combNoRep(int n,int m){
if ((n >= m)&&(m >= 0)){
int num = 1;
int den = 1;
while (m > 0){
den *= m;
num *= n;
m--;
n--;
}
return num/den;
} else return -1;
}
public static int combRep(int n,int m){
return combNoRep(n+m-1,m);
}
public static int perm(int n){
if (n >= 0){
int out = 1;
for (;n > 0;n--)
out *= n;
return out;
} else return -1;
}
}
|