Moneo:

>Sorry, Aga, I don't understand your comments. Please explain.

Never mind the other thing... I got ahead of myself... works if you want to find the biggest number, though.

>Also, would you kindly explain how your algorithm works --- the theory first, then the details

Basically it's exactly like that recursive function above except without the ....useless... pointers.... or useless recursion... :humm:

Pre-algorithm:

1) Start with the string.

2) Convert it to integers.

3) Sort the integers low-high.

4) Remove duplicates.

Algorithm:

What we are doing is a counter with this code:

counter(0) = counter(0) + 1

i=0

2

IF counter(i) > i+1 THEN

counter(i) = 0

i=i+1

IF i = permlength-1 THEN EXIT DO

counter(i) = counter(i) + 1

GOTO 2

END IF

The counter converts to a number that is a set of "digits" of decreasing base, for instance the size 2 number (for "abc") is counted like so:

00 = 0

01 = 1

10 = 2

11 = 3

20 = 4

21 = 5

(I'd use loops but there's already a "do...loop" and neither FB or QB support double loops, like Powerbasic, unfortunately...)

After the counter is moved up one, this code:

FOR i = 0 TO permlength-2

SWAP intperm(i), intperm(counter(permlength-2-i)+i)

NEXT i

...translates the counter to a series of swaps. The counter correlates to all succeeding positions on a permutation tree. For "abcde", the tree loops through all the different characters/values in the first spot, then all the characters in the second spot (one less choice), then all the characters in the third spot, and so on until there are only 2 characters to choose from.

FOR t = 0 TO permlength-1

MID$(tempstring$, t+1,1) = CHR$(intperm(t))

NEXT t: PRINT tempstring$; " ";

FOR i = permlength-2 TO 0 STEP -1

SWAP intperm(i), intperm(counter(permlength-2-i)+i)

NEXT i

This code prints the number and then switches it back. After this, it's looped back to the counter till the counter gets too big. (i = permlength-1)