Anonymous user
Permutations: Difference between revisions
→{{header|PowerBASIC}}
(→{{header|MATLAB}}: works in octave as well) |
|||
Line 2,246:
=={{header|PowerBASIC}}==
<lang powerbasic>
#COMPILE EXE
#DIM ALL
GLOBAL a, i, j, k, n AS INTEGER
GLOBAL d, ns, s AS STRING 'dynamic string
for i=1 to n: a(i)=i: next▼
FUNCTION PBMAIN () AS LONG
ns =
n = VAL(ns)
DIM a(1 TO n) AS INTEGER
do▼
decr i▼
DO
d = STR$(a(i))
s = BUILD$(s, d) ' s & d concatenate
swap a(j),a(k)▼
NEXT
incr j▼
? s 'print and pause
if i>0 then▼
DECR
LOOP UNTIL
j =
k =
DO WHILE j < k
swap a(i),a(j)▼
LOOP
j = i+1
DO WHILE a(j) < a(i)
INCR j
LOOP
END IF
LOOP UNTIL i = 0
END FUNCTION</lang>
=={{header|Prolog}}==
|