| 1 |
use v6; |
| 2 |
|
| 3 |
# start by printing out the header. |
| 4 |
say "Tournament Results:\n"; |
| 5 |
|
| 6 |
my $file = open 'scores.txt'; # get filehandle and... |
| 7 |
my @names = $file.get.words; # ... get players. |
| 8 |
|
| 9 |
my %matches; |
| 10 |
my %sets; |
| 11 |
|
| 12 |
for $file.lines -> $line { |
| 13 |
next unless $line; # ignore any empty lines |
| 14 |
|
| 15 |
my ($pairing, $result) = $line.split(' | '); |
| 16 |
my ($p1, $p2) = $pairing.words; |
| 17 |
my ($r1, $r2) = $result.split(':'); |
| 18 |
|
| 19 |
%sets{$p1} += $r1; |
| 20 |
%sets{$p2} += $r2; |
| 21 |
|
| 22 |
if $r1 > $r2 { |
| 23 |
%matches{$p1}++; |
| 24 |
} else { |
| 25 |
%matches{$p2}++; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
my @sorted = @names.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse; |
| 30 |
|
| 31 |
for @sorted -> $n { |
| 32 |
my $match-noun = %matches{$n} == 1 ?? 'match' !! 'matches'; |
| 33 |
my $set-noun = %sets{$n} == 1 ?? 'set' !! 'sets'; |
| 34 |
say "$n has won %matches{$n} $match-noun and %sets{$n} $set-noun"; |
| 35 |
} |
| 36 |
|
| 37 |
# From https://docs.raku.org/language/101-basics |
| 38 |
|