PDA

View Full Version : Project Euler problem 4



Michael Clease
24-01-2009, 00:19
Here is my solution for problem 4.



' A palindromic number reads the same both ways.
' The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
'
' Find the largest palindrome made from the product of two 3-digit numbers.
uses "Console"

DIM n AS LONG
DIM m AS LONG
DIM Answer AS STRING
DIM rewsnA AS STRING
'...
Dim T1, T2 As QUAD
'---Initialize hi resolution timer
HiResTimer_Init

T1 = hirestimer_get

FOR n = 999 TO 1 STEP -1
FOR m = 999 to 1 STEP -1
Answer = STR$(n*m)
rewsnA = STRREVERSE$(STR$(n*m))
' When the bug is fixed in STR$() the 2 lines above could be removed and the line below used instead.
' IF STR$(n*m) = STRREVERSE$(STR$(n*m)) THEN EXIT FOR FOR
IF mid$(Answer,2,LEN(Answer)-1) = mid$(rewsnA,1,LEN(rewsnA)-1) THEN EXIT FOR FOR
NEXT
NEXT

T2 = hirestimer_get

console_printat ("Answer: " + Answer, 1, 1)
console_printat ("Solution: " + STR$(n) + " * " + STR$(m), 1, 2)
console_printat ("Elapsed time in microseconds: " & FORMAT$(T2-T1, "#0000"),1,3)
console_waitkey