Your code finished in 625ms on my laptop. Very fast!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:

Kind regards,
Francis.
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: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![]()
I wasn't saying that precalculating was cheating, just not including it the total calculation time.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;)
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
I've just gotten around to testing this out on my main workstation.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)
Doh! I've worked out what the problem is.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,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.
Thanks Michael.Michael Vogel wrote:Hi Francis,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.
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.
Here's my solution:michaeled314 wrote:How would you solve #48
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))
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
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