diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-02-15 19:46:28 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-15 19:46:28 +0000 |
| commit | 3c662b7361dda98a6dcc4c9499eeb09370da43a0 (patch) | |
| tree | 77206fa595c2e3a57326a40792b2eaf704ea3e59 | |
| parent | 8f446e972a4866adbb363ac085ccdb8f7041f0b9 (diff) | |
| parent | 6f2fb16b21367a91769cbf75a39e75c38b3873b1 (diff) | |
| download | perlweeklychallenge-club-3c662b7361dda98a6dcc4c9499eeb09370da43a0.tar.gz perlweeklychallenge-club-3c662b7361dda98a6dcc4c9499eeb09370da43a0.tar.bz2 perlweeklychallenge-club-3c662b7361dda98a6dcc4c9499eeb09370da43a0.zip | |
Merge pull request #3535 from stuart-little/stuart-little_fix-100-ch1-raku
clean up ch-1 corner cases
| -rwxr-xr-x | challenge-100/stuart-little/raku/ch-1.p6 | 13 |
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); |
