# Programming Puzzle 29 - Another math treat

• 06-10-2012, 07:02 PM
Tom Cone Jr
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

Enjoy!

Credit for this puzzle: http://www.mathsisfun.com/
• 06-10-2012, 09:36 PM
StephenP
Re: Programming Puzzle 29 - Another math treat
Professor,

I hope my comments are clear. Five lines of code did it.
• 06-10-2012, 09:37 PM
GGandhi
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
• 06-10-2012, 09:47 PM
GGandhi
Re: Programming Puzzle 29 - Another math treat
end to the for next loop

Attachment 32343
• 06-11-2012, 06:07 AM
Tom Cone Jr
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.
• 06-11-2012, 06:12 AM
Tom Cone Jr
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?
• 06-19-2012, 02:22 PM
agillbb
Re: Programming Puzzle 29 - Another math treat
Of course, just for fun, if I was a smart-alic mathematician, I would do this:
Attachment 32456
• 06-19-2012, 02:34 PM
Tom Cone Jr
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.
• 07-18-2012, 03:04 PM
Tony Evans
Re: Programming Puzzle 29 - Another math treat
• 07-18-2012, 03:41 PM
Tom Cone Jr
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