Programming Puzzle 12 - Perfect Squares

Ok, your manager is taking the day off, so you have time to work on a non-business problem.

Take a 3 digit number like 200, reverse it (002) and then multiply the two numbers. The result, 400, is a perfect square ( 20 * 20 = 400 ). Write an xbasic script to find all such 3 digit numbers. Write your list to the trace window. Export your xbasic script and attach it to your reply here.

Courtesy: Creative Computing Magazine

1 Attachment(s)

Re: Programming Puzzle 12 - Perfect Squares

Where is everybody?

As this was my first Xbasic script the form may not be the best. Tom, thank you for the puzzles presented here. Although this was a very easy puzzle I learned a lot. Not the least of which is I have a lot to learn.

Thanks,

Rich Pasma

Re: Programming Puzzle 12 - Perfect Squares

Rich, thanks for taking a crack at puzzle 12.

Prof. Pickypicky has spotted a flaw in your approach.

"I" is not a valid datatype in xbasic.

Consider the following:

Code:

`dim i as I 'we don't have integer datatypes`

i = 12.569

?i

= <No data returned>

dim x as I

x = 22

?x

= <No data returned>

dim j as N 'we have numeric datatypes

'can include decimals, but doesn't

'have to

j = 12.569

?j

= 12.569

Your code produces the right results because Alpha, strangely, does not throw an error when you use an incorrect datatype for your variables. Alpha then "infers" the correct datatype from your expressions, and dimensions them for you.

-- tom

Re: Programming Puzzle 12 - Perfect Squares

Thank you for the corrections. My experience with Excel VBA programing is what caused the confusion with variables. Currently I am plowing through Dr. Peter Wayne’s book on XBasic. Just getting into pointers, it makes sense, but is going to require some practice for me to be able to apply it. Your puzzles with the input from others make a nice addition to the learning experience and have already helped. Great idea. Thanks again.

2 Attachment(s)

Re: Programming Puzzle 12 - Perfect Squares

I have two files below. Puz12org is what was originally asked for. However, since the manager happened to be out all day I play around with the script and designed a new way to show the results and that is the Puz12. Puz12 also holds the proof to my script and the answer.

Attachment 29051

Attachment 29050