# Roger Palay copyright 2016-02-15 # Saline, MI 48176 # num_perm <- function( n, r ) # compute the number of permutations { # of n things taken r at aa time if( r == 0 ) # special case if r=0 {return(1)} p <- 1 # initialize the product for (i in 1:r) # go throgh the r factors { p <- p*n n <- n-1 } return(p) # send back the result } nPr <- function( n,r ) { return (factorial(n)/factorial(n-r))} num_comb <- function( n, r ) { if( r == 0 ) {return(1)} if( r > n/2 ) { r <- n-r} return( num_perm(n,r)/num_perm(r,r)) } nCr <- function(n,r ) { return ( factorial(n)/factorial(n-r)/factorial(r))}