Permutations: Difference between revisions

no edit summary
m (added whitespace.)
No edit summary
Line 3,839:
=={{header|Ring}}==
<lang ring>
aListlist = [1, 2, 3, 4,5]
for perm = 1 to 24
permutation(aList,len(aList))
for i = 1 to len(list)
see aList + nl
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 permutationpermutationReverse a, nfirst, last
for iwhile =first 1< to nlast
temp = a[ifirst]
a[ifirst] = a[nlast]
a[nlast] = temp
next first += 1
return a last -= 1
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}}==
2,468

edits