# Thread: Programming Puzzle 29 - Another math treat

1. ## 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. ## Re: Programming Puzzle 29 - Another math treat

Professor,

I hope my comments are clear. Five lines of code did it.

3. ## 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

4. ## Re: Programming Puzzle 29 - Another math treat

re uploaded file to add
end to the for next loop

Attachment 32343

5. ## 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. ## 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. ## 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. ## 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. ## Re: Programming Puzzle 29 - Another math treat

Answer: Puzzle 29.txt

10. ## 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

#### Posting Permissions

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