Permutations: Difference between revisions

(→‎{{header|MATLAB}}: works in octave as well)
Line 2,246:
 
=={{header|PowerBASIC}}==
<lang powerbasic>defint a-z
#COMPILE EXE
option base 1
#DIM ALL
input "n=",n
GLOBAL a, i, j, k, n AS INTEGER
dim a(n)
GLOBAL d, ns, s AS STRING 'dynamic string
for i=1 to n: a(i)=i: next
FUNCTION PBMAIN () AS LONG
do
ns = forINPUTBOX$(" i=1 to n: print=",, a(i"3");: next:'input printn
n = VAL(ns)
i=n
DIM a(1 TO n) AS INTEGER
do
forFOR i = 1 toTO n: a(i)= i: nextNEXT
decr i
DO
loop until i=0 or a(i)<a(i+1)
js =i+1 " "
kFOR i = 1 TO n
d = STR$(a(i))
while j<k
s = BUILD$(s, d) ' s & d concatenate
swap a(j),a(k)
NEXT
incr j
? s 'print and pause
decr k
wendi = n
doDO
if i>0 then
DECR j=i+1
LOOP UNTIL whilei = 0 OR a(ji) < a(i+1)
j = incr ji+1
k = wendn
DO WHILE j < k
swap a(i),a(j)
swapSWAP a(j), a(k)
end if
decrINCR ij
loop until i=0</lang>
incrDECR jk
LOOP
ifIF i > 0 thenTHEN
j = i+1
DO WHILE a(j) < a(i)
INCR j
LOOP
swapSWAP a(i), a(j)
END IF
LOOP UNTIL i = 0
END FUNCTION</lang>
 
=={{header|Prolog}}==
Anonymous user