What is the greatest perfect square with different digits in ascending order from left to right?
The same, in descending order?
What is the best way to narrow this search?
DEFDBL A-Z
max = SQR(9999999999#)
FOR i = 1 TO max
s = i * i
sq$ = LTRIM$(STR$(s))
good = 1
FOR j = 2 TO LEN(sq$)
IF MID$(sq$, j, 1) <= MID$(sq$, j - 1, 1) THEN good = 0: EXIT FOR
NEXT
IF good THEN PRINT s, i
NEXT
FOR i = 1 TO max
s = i * i
sq$ = LTRIM$(STR$(s))
good = 1
FOR j = 2 TO LEN(sq$)
IF MID$(sq$, j, 1) >= MID$(sq$, j - 1, 1) THEN good = 0: EXIT FOR
NEXT
IF good THEN PRINT s, i
NEXT
finds
1 1
4 2
9 3
16 4
25 5
36 6
49 7
169 13
256 16
289 17
1369 37
13456 116
13689 117
134689 367
as the squares that fit the first pattern, shown with their roots. The largest is 134689.
and:
1 1
4 2
9 3
64 8
81 9
841 29
961 31
as the squares fitting the second pattern, the largest being 961.
|
Posted by Charlie
on 2008-11-23 17:43:16 |