On Dec 3, 2006, at 8:30 PM, Dema wrote:

> Here is my straight-to-the-point answer:

Your solution passes all the unit tests I supplied and is certainly  
good enough to reproduce all the sample designs. So you have good  
reason to think it's completely correct. However, one of the optional  
methods has a problem.

>    # Turn to face the given point.
>    def toward(pt)
>      @heading = atan(pt[0].to_f / pt[1].to_f) / DEG
>    end

This won't work in all four quadrants.

I apologize for not providing tests good enough to detect the  
problem. Here is one that will test all four quadrants.

<code>
    # Test go, toward, and distance.
    # Verify heading measures angles clockwise from north.
    def test_coord_cmnds
       nne = [100, 173]
       @turtle.go nne
       x, y = @turtle.xy
       assert_equal(nne, [x.round, y.round])
       @turtle.home
       @turtle.run { pd; face nne; fd 200 }
       assert_equal(30, @turtle.heading.round)
       assert_equal([[[0, 0], nne]], snap(@turtle.track))
       sse = [100, -173]
       @turtle.home
       @turtle.run { face sse; fd 200 }
       assert_equal(150, @turtle.heading.round)
       ssw = [-100, -173]
       @turtle.home
       @turtle.run { face ssw; fd 200 }
       assert_equal(210, @turtle.heading.round)
       nnw = [-100, 173]
       @turtle.home
       @turtle.run { face nnw; fd 200 }
       assert_equal(330, @turtle.heading.round)
       @turtle.home
       assert_equal(500, @turtle.dist([400, 300]).round)
    end
</code>

Regards, Morton