I have just came up with this simple Python algorithm for generating all the possible permutations from 1 to n, but it does not seem to work. Here is the code:
def main ():
n = 3
x = [0] * 4
k = 1
while k:
ok = True
while x[k] < n and ok:
for i in range (0,k-1):
if x[i] == x[k]:
ok = False
if ok:
x[k] += 1
if x[k] < n:
if k == n:
print x
else:
k+=1
x[k] = 0
else:
k-=1
main()
When I run it, nothing happens. Can you please help me? I am also new to Python