Alpha DevCon 2018
Results 1 to 5 of 5

Thread: Programming Puzzle 12 - Perfect Squares

  1. #1
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default 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

  2. #2
    Member
    Real Name
    Rich Pasma
    Join Date
    Dec 2008
    Posts
    43

    Default 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
    Attached Files Attached Files

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default 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

  4. #4
    Member
    Real Name
    Rich Pasma
    Join Date
    Dec 2008
    Posts
    43

    Default 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.

  5. #5
    Member
    Real Name
    Jeb Richardson
    Join Date
    Aug 2011
    Location
    Bowling Green, KY
    Posts
    26

    Default 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.

    puz12org.txt

    puz12.txt

Similar Threads

  1. Programming Puzzle 2 - Another Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 16
    Last Post: 12-20-2014, 10:38 AM
  2. Programming Puzzle 1 - Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 32
    Last Post: 12-26-2011, 01:38 PM
  3. Programming Puzzle 3 - Fractions, anyone?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 11-08-2011, 05:40 AM
  4. Programming Puzzle 11 - More Loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 11
    Last Post: 08-20-2011, 04:50 PM
  5. Programming Puzzle 10 - Sweets on a budget
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 8
    Last Post: 08-15-2011, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •