fork download
  1. fillrow = function(N,k,pos,array)
  2. {
  3. if (pos == k)
  4. {
  5. array[pos] <- N
  6. print(array)
  7. }
  8. else
  9. {
  10. for (i in 0:N)
  11. {
  12. array[pos] <- i
  13. fillrow(N-i,k,pos+1, array)
  14. }
  15. }
  16. }
  17.  
  18.  
  19. array <- array(10001:10004) # some indentifiable incorrect initial values
  20. fillrow(2,4,1, array)
  21.  
  22.  
Success #stdin #stdout 0.44s 22824KB
stdin
Standard input is empty
stdout
[1] 0 0 0 2
[1] 0 0 1 1
[1] 0 0 2 0
[1] 0 1 0 1
[1] 0 1 1 0
[1] 0 2 0 0
[1] 1 0 0 1
[1] 1 0 1 0
[1] 1 1 0 0
[1] 2 0 0 0