Pinewood Derby Chart (#56)

The three rules of Ruby Q.:

  1. Please do not post any solutions or spoiler discussion for this quiz
    until
    48 hours have passed from the time on this message.

  2. Support Ruby Q. by submitting ideas as often as you can:

http://www.rubyquiz.com/

  1. Enjoy!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Bob S.

I was a Cub Scout leader for five years and one of our favorite
activities was
the annual Pinewood Derby. For you non-Scouts, this is a competition
between
small gravity-powered cars made by the boys using standard kits
containing a
wood block, plastic wheels, and nails for axles. The cars compete
against each
other down a sloping, multi-lane track (2-6 lanes is typical) about 30
feet
long.

Some Cub Scout packs use a “ladder” elimination system for their derby,
but this
isn’t much fun for the boys that are eliminated early. Much more
enjoyable is a
“round-robin” approach that lets each boy’s car run in the same number
of heats,
racing against different opponents each time.

You can find links to more Pinewood Derby information at:

http://members.aol.com/StanDCmr/pwportal.html

This week’s task is to create a Ruby program to generate a chart for a
Pinewood
derby. In order to make the event fair, each car should be scheduled
into each
lane of the track the same number of times (to compensate for any lane
differences due to track imperfections.) We’ll use the term “round” to
refer to
each car running once in each lane. The input to your program will be:

Number of cars
Number of lanes
Number of rounds

For example, let’s assume we have 25 cars and a 4-lane track. If we want
each
car to run twice in each lane (2 “rounds”), that means:

Number of rounds: 2
Number of runs per car: 2 rounds x 4 lanes = 8
Total number of runs: 8 runs/car x 25 cars = 200
Total number of heats: 200 / 4 lanes = 50 heats

So we have to come up with a chart that assigns the cars to lanes and
heats. If
we number the lanes from 1 to 4 and the cars from 1-25, our chart might
look
something like this:

Heat   Lane 1   Lane 2   Lane 3   Lane 4
----   ------   ------   ------   ------
  1:      9        2       13       10
  2:     12        8        5       21
  3:     16       19        6        4
  ...and so on

The trick is to create a chart that is as fair as possible. A “perfect”
chart
would be one in which:

1) Each car runs in the same number of heats
2) Each car runs in each lane an equal number of times
3) Each car runs against every other opponent an equal number of times
4) The heats a car is assigned to are evenly spread throughout the 

event. (In
other words, a boy shouldn’t run in the first 8 heats and then have
to sit
out for the rest of the event.)

In practice, you cannot create a perfect chart for all combinations of
inputs.
For instance, if we ran just one round with our 25 cars, each car would
run in 4
heats and face 12 opponents (3 opponents per heat). Since there are 24
opponents, it isn’t possible to face all the opponents equally. But you
would
want to try to maximize the number of opponents faced, rather than
having two
cars face each other several times.

You may want to create a function to evaluate your chart against the
criteria
above, so you can rank charts as to their “quality”.

The core of my solution is at:

http://users.adelphia.net/~showaltb/rubyquiz/56/derby.rb

It assigns cars by computing a “weight” factor for each car based on the
following criteria:

a) How many times has the car been assigned to this lane?
b) How many times has the car been matched up against the opponents
already slotted to this heat?
c) How long has it been since the car was last scheduled to a heat?

The weight factors act as a bias against selecting a car.

On Nov 28, 2005, at 3:43 PM, Bob S. wrote:

c) How long has it been since the car was last scheduled to a heat?

The weight factors act as a bias against selecting a car.

I dig any Ruby program with a class called ChaoticChart! Seriously,
this is a very interesting solution to read. Must by why you scared
all the others off. You just can’t compete with true chaos. :wink:

James Edward G. II