title: Permutation with repetition without allocate memory
body: <p>I'm looking for an algorithm to generate all permutations with repetition of 4 elements in list(length 2-1000).</p>
  
  <p><a href="http://en.literateprograms.org/Permutations_with_repetition_%28Java%29" rel="nofollow">Java implementation</a></p>
  
  <p>The problem is that the algorithm from the link above alocates too much memory for calculation. It creates an array with length of all possible combination. E.g 4^1000 for my example. So i got heap space exception.</p>
  
  <p>Thank you</p>