June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,8 @@
|
|||
USING: grouping io math.combinatorics math.order prettyprint ;
|
||||
IN: rosetta-code.permutation-sort
|
||||
|
||||
: permutation-sort ( seq -- seq' )
|
||||
[ [ before=? ] monotonic? ] find-permutation ;
|
||||
|
||||
{ 10 2 6 8 1 4 3 } permutation-sort .
|
||||
"apple" permutation-sort print
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
arr := Array([17,0,-1,72,0]):
|
||||
len := numelems(arr):
|
||||
P := Iterator:-Permute(len):
|
||||
for p in P do
|
||||
lst:= convert(arr[sort(convert(p,list),output=permutation)],list):
|
||||
if (ListTools:-Sorted(lst)) then
|
||||
print(lst):
|
||||
break:
|
||||
end if:
|
||||
end do:
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
# Project : Sorting algorithms/Permutation sort
|
||||
# Date : 2018/02/20
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
a = [4, 65, 2, 31, 0, 99, 2, 83, 782]
|
||||
result = []
|
||||
permute(a,1)
|
||||
|
||||
for n = 1 to len(result)
|
||||
num = 0
|
||||
for m = 1 to len(result[n]) - 1
|
||||
if result[n][m] <= result[n][m+1]
|
||||
num = num + 1
|
||||
ok
|
||||
next
|
||||
if num = len(result[n]) - 1
|
||||
nr = n
|
||||
exit
|
||||
ok
|
||||
next
|
||||
see "" + nr + " permutations required to sort " + len(a) + " items." + nl
|
||||
|
||||
func permute(a,k)
|
||||
if k = len(a)
|
||||
add(result,a)
|
||||
else
|
||||
for i = k to len(a)
|
||||
temp=a[k]
|
||||
a[k]=a[i]
|
||||
a[i]=temp
|
||||
permute(a,k+1)
|
||||
temp=a[k]
|
||||
a[k]=a[i]
|
||||
a[i]=temp
|
||||
next
|
||||
ok
|
||||
return a
|
||||
Loading…
Add table
Add a link
Reference in a new issue