aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-100/stuart-little/raku/ch-1.p613
1 files changed, 7 insertions, 6 deletions
diff --git a/challenge-100/stuart-little/raku/ch-1.p6 b/challenge-100/stuart-little/raku/ch-1.p6
index 24c39dac69..b96266fbd0 100755
--- a/challenge-100/stuart-little/raku/ch-1.p6
+++ b/challenge-100/stuart-little/raku/ch-1.p6
@@ -5,12 +5,13 @@ use v6;
sub convTime ($time) {
$time ~~ m/(\d+)\:(\d+)(.*)/;
- (! $2.Str) && ($0.Int == 0) && return qq|{$0+12}:$1| ~ " am";
- (! $2.Str) && ($0.Int < 12) && return $time ~ " am";
- (! $2.Str) && ($0.Int == 12) && return $time ~ " pm";
- (! $2.Str) && ($0.Int > 12) && return qq|{sprintf("%02d", $0-12)}:$1| ~ " pm";
- $2.Str.lc.contains("am") && return qq|$0:$1|;
- $2.Str.lc.contains("pm") && return qq|{$0+12}:$1|;
+ my ($h,$m) = ($0,$1).map(*.Int);
+ my $mode = $2;
+ $mode.Str.lc.contains("am") && return qq|{sprintf("%02d", $h % 12)}:$1|;
+ $mode.Str.lc.contains("pm") && return qq|{sprintf("%02d", ($h % 12) + 12)}:$1|;
+ my $mer = ([0..11].grep($h)) ?? (" am") !! (" pm");
+ my $modh = ([1..12].grep($h)) ?? ($h) !! (($h-12) % 24);
+ return qq|{sprintf("%02d", $modh)}:$1$mer|;
}
say convTime(@*ARGS.join);