Project Euler...

Everything else that doesn't fall into one of the other PB categories.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post 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.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

Stumped on #162. All I can think of is the two billion year way. Anyone have a good algorithm.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: Project Euler...

Post 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
Post Reply