Posted: Mon Nov 12, 2007 11:15 pm
The problem here is that you are not obtaining all of the permutations.michaeled314 wrote:Problem 24 what am I doing wrongCode: Select all
Procedure.s Permutation(String$, n) Protected i, Factorial = 1, Temp For i = 2 To Len(String$) Factorial * (i - 1) Temp = PeekB(@String$ + (i - ((n / Factorial) % i) - 1)) PokeB(@String$ + (i - ((n / Factorial) % i) - 1), PeekB(@String$ + i - 1)) PokeB(@String$ + i - 1, Temp) Next ProcedureReturn String$ EndProcedure Dim Permu.q(1000000) For i = 1 To 1000000 Permu.q(i) = Val(Permutation("0123456789",i)) Next SortArray(Permu.q(),0) Debug Permu.q(1000000)
In order to obtain the number of permutations you will need to work out the factorial (n!) of the number of digits in your string (i.e. "0123456789").
Once you have the complete list of permutations, sort it and then look up the millionth one.
EDIT: Oh, and one more thing. The permutation that you want to look up is actually 999999 instead of a million since the array numbering starts at zero.
Kind regards,
Francis.