rec.puzzles Archive

A computer draws a horizontal line 128 pixels long in n seconds with the command "Plot 0,0 128,0 n".

arithmetic/drawing.pixels New

New entry, edited from material collected for the archive and not yet in a released version.

Problem

A computer draws a horizontal line 128 pixels long in n seconds with
the command "Plot 0,0 128,0 n".  Write the most concise code that draws
64 horizontal pixels in 1 second, then 32 pixels in .5 seconds, then 16
pixels in .25 seconds, then 8 pixels in .125 seconds and so on till you
draw the last pixel (each drawing operation continuing from the last).

The answer is NOT "Plot 0,0 128,0 2", as the sum 64 + 64/2 + 64/4 + ...
continued to infinity would suggest.

-- Mike Warren <mdw95@mailbox.cc.rl.ac.uk>

[ Editor: problem statement condensed from Warren's two postings. ]
Show solution
I take it that what you are getting at is that you can't plot half a
pixel.

thus we plot:

64 in 1/1 sec    total so far =    1/1  sec
32 in 1/2 sec    total so far =    3/2  sec
16 in 1/4 sec    total so far =    7/4  sec
8  in 1/8 sec    total so far =   15/8  sec
4  in 1/16 sec   total so far =   31/16 sec
2  in 1/32 sec   total so far =   63/32 sec
1  in 1/64 sec   total so far =  127/64 sec

that is not only do we not get to 128 pixels, but we don't get to 2
seconds either.

Plot 1,0 127,0 127/64

or

Plot 1,0 127,0 1.984375

if you prefer.

-- Bruce Mills <brucem@cs.uwa.oz.au>