 Thread: Programming Puzzle 24 - So you think you know long division?

1. Programming Puzzle 24 - So you think you know long division?

Puzzle 24 - So you think you know long division?

The professor has discovered a number that has unique properties.

If you divide this number by 2 you get a remainder of 1.
If you divide this number by 3 you get a remainder of 2.
If you divide this number by 4 you get a remainder of 3.
And so on...
The sequence continues until finally, if you divide
this number by 10 you get a remainder of 9!

Your task grasshopper is to write an xbasic program that will
find this number, and display your proof in the Alpha Five
trace window.

In order to avoid negatively impacting the nation's gross
domestic product the professor has a hint for you. The
number is more than 2,000 and less than 3,000.

Bonus points will be awarded to the most efficient solutions.
So include a timer in your code and report the results in
your solution if you try for the bonus points.

Have fun.

Credit EasyCalculation.com for the idea behind this puzzle. 2. Re: Programming Puzzle 24 - So you think you know long division?

hello
here is my solution...
i have not tried timer yet. so i will lose my bonus point
i am also using message box so i will not qualify for anything...
Code:
dim x as n
for x = 2000 to 3000
if mod(x,10)=9
if mod(x,9)=8
if mod(x,8)=7
if mod(x,7)=6
if mod(x,6)=5
if mod(x,5)= 4
if mod(x,4)=3
if mod(x,3)=2
msgbox("The number is ",str(x))
end if
end if
end if
end if
end if
end if
end if
end if
next 3. Re: Programming Puzzle 24 - So you think you know long division?

hello
now i have added elapsed time, also using msgbox - not eligible for anything.
elapsed time shows "0 secs" i am not certain if i am doing the calculation correct.

Code:
dim t1 as y
t1=ctot(time())
dim t2 as y
dim x as n
for x = 2000 to 3000
if mod(x,10)=9
if mod(x,9)=8
if mod(x,8)=7
if mod(x,7)=6
if mod(x,6)=5
if mod(x,5)=4
if mod(x,4)=3
if mod(x,3)=2
t2=ctot(time())
d=(t2-t1)/60
msgbox("Elapsed time","It took "+alltrim(str(d))+" seconds")
end if
end if
end if
end if
end if
end if
end if
end if
next 4. Re: Programming Puzzle 24 - So you think you know long division?

gandhi,

Very nice! You got the correct answer.

I asked Professor Pickypicky to look at your script. Unfortunately, he was a bit cranky since I woke him from his nap. Anyway, he had a few small observations for you.

1) He thinks you should learn to use the trace window. Unlike the message box, the flow of the program is not interrupted when the script writes information to the trace window. Focus does not shift from the running program to the trace window. This can be a real problem in some cases when using msg boxes so it's very useful to know how to work with the trace window.

2) He thinks your program keeps running after the solution is found, does it not? He thinks it unnecessary to keep testing values after the msgbox is displayed. In the interest of efficiency why not exit the For ... Next code block once the solution is found?

3) The professor recommends that you compare the precision of the TIME() and NOW() functions that Alpha supplies. TIME() can't be used to measure intervals smaller than one second.

Thanks for playing. Hope you found it an interesting exercise.

-- tom 5. Re: Programming Puzzle 24 - So you think you know long division?

thanks
1> i changed time() to now() in my test script and it does show result less than 0 secs. (i did not resubmit the code)
2> while building the script i did not exit for loop to see any other number pops up. none popped. i got distracted and did not add exit to the finished product.
3> also i used trace.writeln in my test script and can see the results when i view the trace window.
thanks again. 6. Re: Programming Puzzle 24 - So you think you know long division?

Very good!

The professor is working on another puzzle, so stand by for more fun!  Posting Permissions

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