All the positive perfect squares 1, 4, 9, 16, 25.... are written in strictly ascending order of magnitude and without the commas and spaces, resulting in the following infinite string:
149162536496481100121144......
Reading left to right, what is the 2010th digit in the above pattern?
(In reply to
Computer verification by Jim Keneipp)
In QuickBasic I get a 4 when executing
YEAR = 2010
FOR i = 1 TO 1000
s$ = s$ + STR$(i ^ 2)
IF LEN(s$) >= YEAR THEN EXIT FOR
NEXT i
PRINT MID$(s$, YEAR, 1)
END
because of the space that STR$() gives as the first byte of the string
YEAR = 2010
FOR i = 1 TO 1000
s$ = s$ + LTRIM$(STR$(i ^ 2))
IF LEN(s$) >= YEAR THEN EXIT FOR
NEXT i
PRINT MID$(s$, YEAR, 1)
END
gives the correct 6.
What version of Basic are you using?
|
Posted by Charlie
on 2010-01-28 14:24:29 |