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...
¹) association football somewhere also known as soccer
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.