[R] Recursion in R ...
    Alberto Monteiro 
    albmont at centroin.com.br
       
    Fri Jul  6 20:19:27 CEST 2007
    
    
  
Ted Harding wrote:
>
> So I slickly wrote a recursive definition:
> 
> Nnk<-function(n,k){
>   if(n==1) {return(k)} else {
>     R<-0;
>     for(r in (1:k)) R<-(R+Nnk(n-1,k-r+1)) # ,depth))
>   }
>   return(R)
> }
> 
You are aware that this is equivalent to:
Nnk1 <- function(n, k) { prod(1:(n+k-1)) / prod(1:n) / prod(1:(k-1)) }
aren't you?
 
> ON THAT BASIS: I hereby claim the all-time record for inefficient
> programming in R.
> 
> Challengers are invited to strut their stuff ...
> 
No, I don't think I can bet you unintentionally, even though
my second computer program that I ever wrote in life had to be
aborted, because it consumed all the resources of the computer.
Alberto Monteiro
    
    
More information about the R-help
mailing list