#!/usr/local/bin/perl6

# Solution to Advanced Event 2, 2008 scripting games, http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent2.mspx

use v6;
my %players;
my $scores = open('./skaters.txt', :r) or die $!;
my $name;
my @list;

for =$scores {
    ($name,@list) = .split(/\,/);
    @list .=sort;
    %players{$name} = ([+] @list[2..6]) / 5;
};

my @ranking = %players.sort: { .value };
for <Gold Silver Bronze> -> $m {
    given pop @ranking {
	say "$m Medal: " ~ %players{$_} ~ ', ' ~ $_;
#	say "$m Medal: $_";
    };
};
