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 »

Michael Vogel wrote:Hi,
my notebook seems to be very lazy (takes 6 seconds to finish Francis' code), so maybe my solution could be fast on your machines:
Your code finished in 625ms on my laptop. Very fast! :D

Kind regards,

Francis.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Michael Vogel wrote:I think, its quite interesting how many different approaches are possible - we are "only" three programmer and everyone found a (totaly) personal way to implement the thing :wink:
What amazes me even more is how some of my solutions are almost identical to some of the other solutions in the way they are written.
Michael Vogel wrote:And btw I agree also, that precalculation (of squares etc) is not cheating, it's part of a strategy (and part of the total calculation time;)
I wasn't saying that precalculating was cheating, just not including it the total calculation time.

Kind regards,

Francis.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Hm,

whats on? During the last weeks I had some few days where I had time to think about some problems, but only solved one (and not very efficient as well, the code ran about an hour or so), but had no success with any other problem, on some I don't have even an idea...

So these are still mising:
110, 118, 131, 132, 133, and all problems from 135 on

Code: Select all

; -- First check for problem 135 --
n=1155
;n=27

For x=1 To 10000; when I can stop???
	qx=x*x
	For i=1 To x>>1
		y=x-i
		z=y-i
		If qx-y*y-z*z=n
			Debug Str(x)+#TAB$+Str(y)+#TAB$+Str(z)
		EndIf
	Next i
Next x
And whats about you? Did you solve any problem? Do you need a hint for another one?

Michael
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

I had a quick try of problem 118, but I couldn't get a working solution so I've went back to solving some of the gaps I had. It took me a while and three different approaches to get a satisfactory solution for number 15!

Kind regards,

Francis.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Demivec wrote:@Dreamland Fantasy:
The routine to test the general case test faster on my machine, will you test it on yours to verify? The palindrome routines are used in several of the Problems and I think to have them operate as quickly as possible would definately be helpful (though for problem 4 it's a bit of an overkill :wink: )
I've just gotten around to testing this out on my main workstation.

Demivec Routine completes in an average time of 1.605ms and Demivec Routine 2 completes in an average time of 1.646ms.

Kind regards,

Francis.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

I really hate to ask, but I am having problems with problem 37. My problem is that I am getting 26 truncatable prime numbers when the problem states that there should only be 11! :?

The numbers I get are 11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131, 137, 173, 197, 311, 313, 317, 373, 797, 1373, 1997, 3137, 3797, 7331, 73331 and 739397.

Maybe I am misunderstanding the problem.

I'm not looking for the full solution, just a nod in the right direction.

Kind regards,

Francis.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Michael Vogel wrote:So these are still mising:
110, 118, 131, 132, 133, and all problems from 135 on
Problem 145 is quite easy. :)

Kind regards,

Francis.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Dreamland Fantasy wrote:I really hate to ask, but I am having problems with problem 37. My problem is that I am getting 26 truncatable prime numbers when the problem states that there should only be 11! :?

The numbers I get are 11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131, 137, 173, 197, 311, 313, 317, 373, 797, 1373, 1997, 3137, 3797, 7331, 73331 and 739397.

Maybe I am misunderstanding the problem.

I'm not looking for the full solution, just a nod in the right direction.

Kind regards,

Francis.
Doh! I've worked out what the problem is. :oops:

Kind regards,

Francis.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Dreamland Fantasy wrote:I really hate to ask, but I am having problems with problem 37. My problem is that I am getting 26 truncatable prime numbers when the problem states that there should only be 11! :?

The numbers I get are 11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131, 137, 173, 197, 311, 313, 317, 373, 797, 1373, 1997, 3137, 3797, 7331, 73331 and 739397.

Maybe I am misunderstanding the problem.

I'm not looking for the full solution, just a nod in the right direction.

Kind regards,

Francis.
Hi Francis,
be careful, you have to many numbers (at least at the beginning):

1 is not a prime, so 11 can't be taken, but also 13 (because it must work from left to roght AND right to left) etc.

So the only numbers below 100 are 23, 37, 53, 73.

Hope that helps,
Michael

EDIT - oops, too late, sorry.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Michael Vogel wrote:
Dreamland Fantasy wrote:I really hate to ask, but I am having problems with problem 37. My problem is that I am getting 26 truncatable prime numbers when the problem states that there should only be 11! :?

The numbers I get are 11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131, 137, 173, 197, 311, 313, 317, 373, 797, 1373, 1997, 3137, 3797, 7331, 73331 and 739397.

Maybe I am misunderstanding the problem.

I'm not looking for the full solution, just a nod in the right direction.

Kind regards,

Francis.
Hi Francis,
be careful, you have to many numbers (at least at the beginning):

1 is not a prime, so 11 can't be taken, but also 13 (because it must work from left to roght AND right to left) etc.

So the only numbers below 100 are 23, 37, 53, 73.

Hope that helps,
Michael

EDIT - oops, too late, sorry.
Thanks Michael.

I spent a couple of hours on this problem last night. It's only when I looked at it this morning with fresh eyes I saw what the problem was! :roll:

Kind regards,

Francis.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

How would you solve #48
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:How would you solve #48
Here's my solution:

Code: Select all

#Title = "Problem 48"

#Mod = 10000000000
  
Result.q = 1
  
For i = 2 To 999
  If i % 10
    a.q = i
    For j = 1 To i - 1
      a = (a * i) % #Mod
    Next
    Result = (Result + a) % #Mod
  EndIf
Next

MessageRequester(#Title, "Result = "+StrQ(Result))
Kind regards,

Francis.
mike74
User
User
Posts: 60
Joined: Mon Nov 21, 2005 1:44 pm

Post by mike74 »

A question that occurred to me while thinking about Problem 88: What is the best way to get a number's unique factorizations (a.k.a. unordered factorizations according to Mathworld)? A clue might be the solution to the "Refactoring" problem at http://www.topcoder.com/tc?module=Stati ... &d2=srm216, which counts the unique factorizations. I converted the answer to that problem to PB code, but I'm having trouble figuring out how to use it to list the factorizations. Any ideas? Here's my PB code, with code commented out that might provide some insight into the direction I was going in:

Code: Select all

Global total = 0

Procedure.s getuniquefactors(g.l, lastfactor.l, x.l)

i = lastfactor
resstring.s = ""
While i*i<=g
    If g%i = 0 
        resstring = Str(g/i) + " " + getuniquefactors(g/i, i, x)
        Debug Str(g) + "-" + Str(i)
        total + 1
    Else
        resstring = Str(g)
    EndIf
i + 1
Wend
; multot.l = 1: z = 1
; While z <= CountString(resstring, " ") + 1
; Debug (resstring) + ", " + Str(multot) + ", " + StringField(resstring, z, " ")
; multot * Val(StringField(resstring, z, " "))
; z + 1
; Wend
; Debug Str(x) + " " + Str(multot) +"."
; If multot = x
; Debug "."+resstring
; EndIf
ProcedureReturn resstring
EndProcedure

getuniquefactors(9240, 2, 9240)
Debug total
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Dreamland Fantasy wrote: Problem 145 is quite easy. :)
Francis.
Thanks, got it... :D

Searching for problems 110, 118, 131, 132, 133, 135 to 144 and all from 146 on...
mike74
User
User
Posts: 60
Joined: Mon Nov 21, 2005 1:44 pm

Post by mike74 »

I think I answered my question!

Code: Select all

Global total = 0
Global Dim iterdepth.l(50)
Procedure.s getuniquefactors(g.l, lastfactor.l, x.s)

i = lastfactor
resstring.s = ""
While i*i<=g
If g%i = 0 
     iterdepth(i) + 1
     x = x + "-" + Str(i)
     Debug x + "-" + Str(g/i)
     resstring = Str(g/i) + " " + getuniquefactors(g/i, i, x)
     total + 1
     While Right(x, 1) <> "-"
         x = Left(x, Len(x) - 1)
     Wend
     x = Left(x, Len(x) - 1)
EndIf
i + 1
Wend
ProcedureReturn resstring
EndProcedure

getuniquefactors(72, 2, "")
Debug total
End
:D

Edit: Removed an Else that prevented solutions for odd input.
Last edited by mike74 on Thu Jul 12, 2007 11:01 pm, edited 1 time in total.
Post Reply