Assignment 6 fix.


R. Clayton (rclayton@clayton.cs.monmouth.edu)
(no date)


It was brought to my attention last night that assignment 6 core dumps when the
building has one floor. Because it doesn't make much sense to put an elevator
in a one-story building, I've fixed the problem by requiring that all buildings
have at least two floors; see the updated assignment page for details.

For the interested, the problem occurred in the way I computed the destination
for a waiter on floor f in a building with t floors:

  unsigned make_destination(unsigned f, unsigned t) {
    unsigned d = (f + (random() % (t - 1)) + 1) % t;
    assert(d != f);
    return d;
    }

When t = 1, random() % 0 has undefined behavior. Without the core dump, this
would have been an exceptionally nasty problem to find because of the second
mod reduction.

Although I described the fix above, I also changed the destination routine:

  unsigned make_destination(unsigned f, unsigned t) {
    assert(t > 1);
    unsigned d = (f + (random() % (t - 1)) + 1) % t;
    assert(d != f);
    return d;
    }

It is a general law of human nature that if you screw something up one way,
chances are good that you'll screw it up again exactly the same way in the
future.



This archive was generated by hypermail 2.0b3 on Fri Dec 21 2001 - 17:00:04 EST