Created
October 23, 2011 09:26
-
-
Save tadzik/1307166 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
┌─[tadzik@yavin4]─[~/src/book] (master) | |
└─[%]─> 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 | |
┌─[tadzik@yavin4]─[~/src/book] (master) | |
└─[%]─> cat dupa.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"; | |
} | |
┌─[tadzik@yavin4]─[~/src/book] (master) | |
└─[%]─> perl6 dupa.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 | |
┌─[tadzik@yavin4]─[~/src/book] (master) | |
└─[%]─> perl6 --version | |
This is perl6 version 2011.10-11-g5b16dbe built on parrot 3.9.0 revision RELEASE_3_9_0-5-g2206ed8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment