With less than two weeks before the Football World Cup kicks off, the office sweep has appeared. I wrote the following script to help me with the group stage predictions. It makes its predictions based on the FIFA rankings:
#!/usr/bin/perl use strict; use warnings; # The following statistics are from # http://www.fifa.com/en/mens/statistics/index/0,2548,All-May-2006,00. +html my %FIFA_points = ("Brazil" => 827, "Czech Republic" => 772, "Holland" => 768, "Mexico" => 758, "Spain" => 756, "USA" => 756, "Portugal" => 750, "France" => 749, "Argentina" => 746, "England" => 741, "Italy" => 728, "Sweden" => 709, "Japan" => 705, "Germany" => 696, "Tunisia" => 693, "Iran" => 686, "Croatia" => 686, "Costa Rica" => 683, "Poland" => 677, "South Korea" => 677, "Ivory Coast" => 669, "Paraguay" => 653, "Saudi Arabia" => 651, "Switzerland" => 648, "Ecuador" => 631, "Australia" => 612, "Serbia & Montenegro" => 610, "Ukraine" => 609, "Trinidad & Tobago" => 604, "Ghana" => 600, "Angola" => 581, "Togo" => 569 ); my %groups = (A => ["Germany", "Costa Rica", "Poland", "Ecuad +or"], B => ["England", "Paraguay", "Trinidad & Tobago", "Swede +n"], C => ["Argentina", "Ivory Coast", "Serbia & Montenegro", "Holla +nd"], D => ["Mexico", "Iran", "Angola", "Portu +gal"], E => ["USA", "Czech Republic", "Italy", "Ghana +"], F => ["Australia", "Japan", "Brazil", "Croat +ia"], G => ["South Korea", "Togo", "France", "Switz +erland"], H => ["Spain", "Ukraine", "Tunisia", "Saudi + Arabia"] ); my @combinations = ([0, 1], [2, 3], [0, 2], [3, 1], [3, 0], [1, 2]); for ("A" .. "H") { print STDERR "\nGroup $_:\n"; my $group = $groups{$_}; foreach (@combinations) { my $a = $group->[$_->[0]]; my $b = $group->[$_->[1]]; my $home_advantage = $FIFA_points{$a} - $FIFA_points{$b}; my $score = get_score($home_advantage); print STDERR "$a vs $b ($score)\n"; } } sub get_score { my ($points_diff) = @_; my $score = 0; my $other = 0; if (abs $points_diff <= 30) { $score = 0; } elsif (abs $points_diff <= 80) { $score = 1; } elsif (abs $points_diff <= 130) { $score = 2; } elsif (abs $points_diff <= 200) { $score = 3; } else { $score = 4; } my $random_factor = rand; if ($random_factor > 0.9) { $score += 2; $other += 2; } elsif ($random_factor <= 0.9 and $random_factor > 0.75) { $score += 1; $other += 1; } if ($points_diff == abs $points_diff) { return "${score}-${other}"; } else { return "${other}-${score}"; } }


Any comments or suggested improvements would be gratefully received.

In reply to Football World Cup Group Stage Predictor. by perlmoth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.