Page 13 of 13

Posted: Mon Nov 12, 2007 11:15 pm
by Dreamland Fantasy
michaeled314 wrote:

Code: 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)
Problem 24 what am I doing wrong
The problem here is that you are not obtaining all of the permutations.

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.

Posted: Sat Dec 08, 2007 6:42 pm
by michaeled314
Stumped on #162. All I can think of is the two billion year way. Anyone have a good algorithm.

Re: Project Euler...

Posted: Fri Nov 28, 2014 12:34 pm
by Dreamland Fantasy
Hi there,

I've just started getting back into solving the Project Euler problems again.

If anyone wants to add me as a friend on Project Euler my key is 12632_5a24be42a73d1c8ee68b8d642d58647d

Kind regards,

Francis