Alpha DevCon 2018
Results 1 to 6 of 6

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

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

    Default 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. #2
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

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

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

    Default 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("The answer is",str(x))
    				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
    Last edited by GGandhi; 05-29-2012 at 05:55 AM. Reason: added alltrim
    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
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,300

    Default 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. #5
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

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

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

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

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 22 - What do you Mean?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 5
    Last Post: 05-23-2012, 07:09 AM
  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 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
  •