Permutations: Difference between revisions
no edit summary
m (added whitespace.) |
No edit summary |
||
Line 3,839:
=={{header|Ring}}==
<lang ring>
for perm = 1 to 24
for i = 1 to len(list)
see list[i] + " "
next
see nl
nextPermutation(list)
next
func nextPermutation a
elementcount = len(a)
if elementcount < 1 then return ok
pos = elementcount-1
while a[pos] >= a[pos+1]
pos -= 1
if pos <= 0 permutationReverse(a, 1, elementcount)
return ok
end
last = elementcount
while a[last] <= a[pos]
last -= 1
end
temp = a[pos]
a[pos] = a[last]
a[last] = temp
permutationReverse(a, pos+1, elementcount)
func
temp = a[
a[
a[
end
</lang>
Output:
<pre>
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321
</pre>
=={{header|Ruby}}==
|