Haiku has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Need a scheduling algorithm
by Abigail-II (Bishop) on Aug 29, 2002 at 16:40 UTC
    Since your requirements don't prohibit teams playing against another team multiple times, you can just shuffle the teams and pick them two-by-two. Here's one way:
    use strict; use warnings; my @teams = qw { Mice Squirrels Snails Fish Frogs Bees Sparrows Snakes Camels Leeches }; sub shuffle { foreach (my $i = @_; -- $i;) { my $r = rand ($i + 1); @_ [$i => $r] = @_ [$r => $i]; } @_; } my $rounds = shift || 5; foreach (1 .. $rounds) { my @pairing = shuffle @teams; while (@pairing) { my ($home, $away) = splice @pairing => 0, 2; printf "%20s - %20s\n" => $home, $away; } print "---\n"; } __END__ Snakes - Snails Sparrows - Mice Bees - Frogs Fish - Leeches Camels - Squirrels --- Leeches - Frogs Mice - Snails Fish - Camels Squirrels - Snakes Sparrows - Bees --- Bees - Squirrels Mice - Leeches Frogs - Sparrows Snails - Snakes Camels - Fish --- Frogs - Sparrows Camels - Squirrels Snails - Bees Fish - Mice Snakes - Leeches --- Mice - Camels Fish - Snails Leeches - Frogs Squirrels - Bees Sparrows - Snakes ---
    Abigail