Demivec wrote:Dreamland Fantasy wrote:I'm still trying to optimise problem 125 as it currently takes just over a minute to complete on my laptop
My version ran in 8.063 seconds.

I've managed to get mine down from 63 seconds to under 35 seconds.
The reason mine is so slow is probably due to the way I approached the problem which was to go through all the numbers under 10^8, check if they were a palindrome (which is where my algorithm spends about 95% of its time) and then check if it has a valid consecutive number sequence. On the plus side doing it this way means that you don't need to bother about checking for duplicates they way most of the guys on the Project Euler forum have.
To get mine as fast as yours I would need to rewrite the algorithm so that I'm not going through all of the potential numbers.
Incidentally, I found a marginally faster way (from my original) of checking for palindromes.
Code: Select all
Procedure IsPalindrome(A$)
Protected i, length = Len(A$) - 1
For i = 0 To length
If PeekB(@A$ + i) = PeekB(@A$ + length - i)
Else
ProcedureReturn 0
EndIf
Next
ProcedureReturn 1
EndProcedure
The only change I made was to use '=' instead of '<>' in the if statement and then do a procedure return on the else statement.
I suspect that doing it this way might be faster because you are not doing two checks (the '<' and '>') and are thus reducing the overheads.
Kind regards,
Francis.