Skip to content

Instantly share code, notes, and snippets.

@JEEN
Created April 1, 2010 06:13
Show Gist options
  • Select an option

  • Save JEEN/351453 to your computer and use it in GitHub Desktop.

Select an option

Save JEEN/351453 to your computer and use it in GitHub Desktop.
use v6;
my $file = open 'scores';
my @names = $file.get.split(' ');
my %games;
my %sets;
for $file.lines -> $line {
my ($pairing, $result) = $line.split(' | ');
my ($p1, $p2) = $pairing.split(' vs ');
my ($r1, $r2) = $result.split(':');
%sets{$p1} += $r1;
%sets{$p2} += $r2;
if $r1 > $r2 {
%games{$p1}++;
} else {
%games{$p2}++;
}
}
#my @sorted = @names.sort({ %sets{$_} }).sort({ %games{$_} }).reverse;
my @sorted = @names.sort({ %sets{$_} }).reverse.sort({ %games{$_} });
for @sorted -> $n {
say "$n has won { %games{$n} } game and { %sets{$n} } sets";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment