Alpha DevCon 2018
Results 1 to 10 of 10

Thread: Programming Puzzle 29 - Another math treat

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

    Default Programming Puzzle 29 - Another math treat

    Puzzle 29

    If you prepend a 1 to a five digit number, the result
    is exactly 3 times smaller than if you appended a 1 to
    the same five digit number. What's the five digit number?

    i.e. Assume a five digit number NNNNN
    1NNNNN is exactly 3 times smaller than
    NNNNN1. What is NNNNN?

    The "professor" thinks this is too easy, but I insisted you needed a break after Puzzle 28, so
    have fun. Don't let conversion from string to numeric to string to numeric to string, and so on, drive
    you crazy!

    Your task boys and girls is to write an xbasic script that solves this puzzle. Display your
    answer in the trace window. For extra credit don't post your script in the body of a reply,
    but figure out how to "export" your script to a text file, and then "attach" your text file
    to your reply here.

    Enjoy!



    Credit for this puzzle: http://www.mathsisfun.com/

  2. #2
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    490

    Default Re: Programming Puzzle 29 - Another math treat

    Professor,

    I hope my comments are clear. Five lines of code did it.
    Attached Files Attached Files
    Stephen Pilon
    Associate Librarian
    Christendom College

  3. #3
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Programming Puzzle 29 - Another math treat

    hello
    here is mine
    answer in three places 1> message box, 2> trace window 3> status bar - overkill?

    Attachment 32339
    Last edited by GGandhi; 06-10-2012 at 09:43 PM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  4. #4
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Programming Puzzle 29 - Another math treat

    re uploaded file to add
    end to the for next loop

    Attachment 32343
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

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

    Default Re: Programming Puzzle 29 - Another math treat

    gandhi,

    Very nice! When I saw your solution I woke the "professor" up to show it to him. He was his usual grumpy sellf, and muttered something about EXIT FOR before falling back asleep. You might check it out in the helps, since that can be a better way to jump out of a FOR ... NEXT loop.

    Good work.

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

    Default Re: Programming Puzzle 29 - Another math treat

    Stephen,

    Very nice!

    You did a great job of narrowing the range of values to be checked. Your decision to step through the values 30 at a time was inspired. In my own solution I was looking for a way to "spin" the 10's digit ten at a time, without noticing that the script could be speeded up by spinning 30 at a time. Have you studied with the "professor" before?

  7. #7
    "Certified" Alphaholic
    Real Name
    Andy Gill
    Join Date
    Jul 2011
    Location
    Barbados
    Posts
    1,028

    Default Re: Programming Puzzle 29 - Another math treat

    Of course, just for fun, if I was a smart-alic mathematician, I would do this:
    justforfun.txt

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

    Default Re: Programming Puzzle 29 - Another math treat

    Andy, your solution illustrates another approach altogether. The key to all of these puzzles is figuring out how to express the problem in terms the machine can understand. Thanks for showing us a different way.

  9. #9
    Member
    Real Name
    Tony Evans
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    46

    Default Re: Programming Puzzle 29 - Another math treat

    Answer: Puzzle 29.txt

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

    Default Re: Programming Puzzle 29 - Another math treat

    Very good, Tony.

    You should read up on "exporting" and "importing" scripts. The professor awards "extra credit" if solutions are pre-formatted for easy import. The same technique can be a big help in maintaining customer databases, as well. Much better than copying and pasting, or using simple text files.

    -- tom

Similar Threads

  1. Programming Puzzle 23 - For / Next Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 9
    Last Post: 07-18-2012, 06:54 PM
  2. Programming Puzzle 28 - Alphabet Math?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 10
    Last Post: 06-10-2012, 04:46 PM
  3. Programming Puzzle 22 - What do you Mean?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 5
    Last Post: 05-23-2012, 07:09 AM
  4. Programming Puzzle 21 - Got ini ?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 5
    Last Post: 09-08-2011, 09:19 PM
  5. Programming Puzzle 11 - More Loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 11
    Last Post: 08-20-2011, 04:50 PM

Bookmarks

Posting Permissions

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