I use two digits in an integer to represent one element. I.e. 3345512
represents the four elements [3,34,55,12]
. Next, I repeatedly add one to the integer to get another sequence of elements. When generating the sequences like this, I get permutations of the same sequence, i.e. 3341255 = [3,34,12,55]
, which in my case is equivalent to the number 3345512 = [3,34,55,12]
. So I would like to avoid permutations of a sequence I already encountered. I do not want to store the numbers as they grow very large (10^30
and more). I tried to use a bloom filter, but it could not handle the amount of elements. Is there a trivial solution to generate the sequences without permutations?
[EDIT] Here is a tiny python script, that should work. For the sake of better comprehensibility, I use a single digit with if s[idx] == 9:
instead of if s[idx] == 99:
If you have a more simple solution I will accept it as an answer.
import time
s = [1]
while True:
idx = 0
while not idx+1 == len(s) and not s[idx] < s[idx+1]:
s[idx] = 1
idx += 1
if s[idx] == 9:
s[idx] = 1
s.append(1)
else:
s[idx] += 1
print repr(s)
time.sleep(0.7)