Created
October 23, 2011 09:39
-
-
Save snarkyboojum/1307178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl6 --version | |
This is perl6 version 2011.09-15-g991ade7 built on parrot 3.8.0 revision RELEASE_3_8_0-120-gb7e7400 | |
$ cat scores | |
Beth Ana Charlie Dave | |
Ana Dave | 3:0 | |
Charlie Beth | 3:1 | |
Ana Beth | 2:3 | |
Dave Charlie | 3:0 | |
Ana Charlie | 3:1 | |
Beth Dave | 0:3 | |
$ cat 1.1.pl | |
use v6; | |
my $file = open 'scores'; | |
my @names = $file.get.words; | |
my %matches; | |
my %sets; | |
for $file.lines -> $line { | |
my ($pairing, $result) = $line.split(' | '); | |
my ($p1, $p2) = $pairing.words; | |
my ($r1, $r2) = $result.split(':'); | |
%sets{$p1} += $r1; | |
%sets{$p2} += $r2; | |
if $r1 > $r2 { | |
%matches{$p1}++; | |
} else { | |
%matches{$p2}++; | |
} | |
} | |
my @sorted = @names.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse; | |
for @sorted -> $n { | |
say "$n has won %matches{$n} matches and %sets{$n} sets"; | |
} | |
$ perl6 1.1.pl | |
Nominal type check failed for parameter '$limit'; expected Int but got Whatever instead | |
in method words at src/gen/CORE.setting:3135 | |
in block <anon> at 1.1.pl:4 | |
in <anon> at 1.1.pl:1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment