Update: Originally, I stated that this was all that's possible, but as blokhead points out non 2n solutions with backtracking is possible.#!/usr/bin/perl -w use strict; my @name = qw(a b c d e f g h); die "You must have an even number of players" if @name % 2; my %tournament; $tournament{$_} = [] for @name; for my $round (1 .. $#name) { $round--; for my $player (@name) { next if $tournament{$player}->[$round]; for my $opponent (@name) { next if $opponent eq $player; next if $tournament{$opponent}->[$round]; next if @{$tournament{$player}} && grep /^$opponent$/ , @{ +$tournament{$player}}; $tournament{$player}->[$round] = $opponent; $tournament{$opponent}->[$round] = $player; last; } } } for my $round (1 .. $#name) { $round--; print "\n\nRound: $round\n"; my %seen; for my $player (@name) { next if $seen{$player}; print "$player plays $tournament{$player}->[$round]\n"; $seen{$tournament{$player}->[$round]} = 1; } }
Hope this gets you started - L~R
In reply to Re: Round robin tournament problem
by Limbic~Region
in thread Round robin tournament problem
by CiceroLove
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |