Created
October 23, 2011 10:59
-
-
Save masak/1307245 to your computer and use it in GitHub Desktop.
This is how it looks for me
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
masak@ubuntu:~/tmp$ 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 | |
masak@ubuntu:~/tmp$ cat players.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"; | |
} | |
masak@ubuntu:~/tmp$ perl6 --version | |
This is Rakudo Perl 6, version 2011.06-9-gf63b825 built on parrot 3.5.0 RELEASE_3_5_0-228-g6241045 | |
Copyright 2008-2011, The Perl Foundation | |
masak@ubuntu:~/tmp$ perl6 players.pl | |
Ana has won 2 matches and 8 sets | |
Dave has won 2 matches and 6 sets | |
Charlie has won 1 matches and 4 sets | |
Beth has won 1 matches and 4 sets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment