Skip to content

Instantly share code, notes, and snippets.

@tadzik
Last active December 16, 2015 21:09
Show Gist options
  • Save tadzik/5497390 to your computer and use it in GitHub Desktop.
Save tadzik/5497390 to your computer and use it in GitHub Desktop.
my $data = [
{ song => "Follow Me Back Into The Sun", duration => "4:18" },
{ song => "The City And The River", duration => "4:02" },
{ song => "Stay Over", duration => "3:17" },
{ song => "Stranger Keeper", duration => "3:30" },
{ song => "You're Not Listening", duration => "4:11" },
{ song => "Never Gonna Give You Up", duration => "9964:11" },
];
use MONKEY_TYPING;
augment class Duration {
multi method gist {
my ($d, $h, $m, $s) = 0 xx 4;
my $T = $.x.Int;
($d, $T) = ($T div 86400, $T % 86400);
($h, $T) = ($T div 3600, $T % 3600);
($m, $T) = ($T div 60, $T % 60);
$s = $T;
"$d days, $h hours, $m minutes and $s seconds"
}
}
sub total-time(@songs) {
my $total;
for @songs {
my ($m, $s) = $_<duration>.split(':');
$total += $s + 60 * $m;
}
return Duration.new($total).gist
}
say "Total time is ", total-time($data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment