[Tutor] Interview questions in python and wxpython

bob gailer bgailer at alum.rpi.edu
Sun Jan 20 00:10:36 CET 2008


Ricardo Aráoz wrote:
>
> Ok, I'll bite.
> First, the instructions make no sense. There is no left and right! In a
> railroad there is forward and backwards, and these are relative to the
> directions the cars dropped at which I assume will be random. So "move
> fwd" has the same meaning as "move bck" as there is no common reference
> system (at least you mentioned none).
>
> Anyway the program is obvious:
>
> label1
> Move one car's length fwd
> If car is next to a parachute Goto label2
> do nothing
> goto label1
>
> label2
> Move one car's length fwd
> goto label2
>
>
> This will give you 75% probability that the cars meet (they will never
> meet if they land facing opposite ways).
>
>   
When the problem was posed to me there was a diagram in which left and 
right made sense. Your observation is also good.

The program is obvious - well eventually. It took me several iterations 
before I was able to see the obvious.

My preferred solution is the one Michael Langford offered as this makes 
no assumptions about execution time:

#Same assumptions as 1, but assumes:
# NO-OP takes no time to execute
# so we have to move the car around more
# to slow it down
#Approach: Two steps forward, one step back,
# until we're sure we're the chasing car
PROG2:  GO LEFT
        GO LEFT
    GO RIGHT
    IF AT PARACHUTE GOTO FASTER
    GOTO PROG2
FASTER: GO LEFT
    GOTO FASTER


More information about the Tutor mailing list