http://qs321.pair.com?node_id=1009940

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

The UEFA Champions League is the uber league for European club football¹, combining the best teams of different associations.

Now some conspiracy theories came up after the last drawings for the next round, because an UEFA official predicted the exact pairings at a test screening.

ATM a German news paper tried to calculate the likelihood for this to happen and said that the rules are too complicated for a mathematical approach and a computer program counted 5463 possible pairings

from http://www.uefa.com/newsfiles/19071.pdf

First knockout round 6.07 The first knock-out round pairings are determined by means of a d +raw. The first knockout round is played under the cup (knock-out) system, +on a home- and-away basis (two legs). The UEFA administration ensures that t +he following principles are respected. a) Clubs from the same association must not be drawn against each + other. b) The winners and runners-up of the same group must not be drawn against each other. c) The group-winners must not be drawn against each other. d) The runners-up must not be drawn against each other. e) The runners-up must play the first leg at home.

Now I tried the same, with the following script I counted also 5463 possible pairings.

#!perl use strict; use warnings; my @first = qw(Paris Schalke Malaga Dortmund Turin Bayern Barcelon +a ManU); my @second= qw(Porto Arsenal Mailand Madrid Donezk Valencia Celtic + Galatasaray); my @england = qw(ManU Arsenal); my @italy = qw(Turin Mailand); my @spain = qw(Barcelona Malaga Valencia Madrid); my @drawn; my %count_hash; my $count; draw_match(); print $count,"\n", scalar keys %count_hash; sub draw_match { my $first = $first[scalar @drawn]; unless ( $first) { print "@drawn\n"; $count++; $count_hash{"@drawn"}=1; return; } for my $second (@second) { next if $second ~~ @drawn; next if not allowed($first,$second); push @drawn, $second; draw_match(); pop @drawn; } } sub allowed { my ($first,$second)=@_; return if $second eq $second[scalar @drawn]; # same grou +pstage? return if $first ~~ @england and $second ~~ @england; return if $first ~~ @italy and $second ~~ @italy; return if $first ~~ @spain and $second ~~ @spain; return 1; }

It's the first time that I used the smart match as an in-operator in arrays, it's not the most efficient way but it clarifies the program logic

I came pretty far with pencil and paper, but the edge cases for teams from the same qualification group take too much effort...

UPDATE:

Anyway I'm not sure that all possible combinations have the same probability to happen...

Cheers Rolf

¹) association football somewhere also known as soccer