diff options
| -rwxr-xr-x | challenge-347/feng-chang/raku/ch-1.raku | 7 | ||||
| -rwxr-xr-x | challenge-347/feng-chang/raku/ch-2.raku | 10 | ||||
| -rwxr-xr-x | challenge-347/feng-chang/raku/test.raku | 29 |
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-347/feng-chang/raku/ch-1.raku b/challenge-347/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..37756d5359 --- /dev/null +++ b/challenge-347/feng-chang/raku/ch-1.raku @@ -0,0 +1,7 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s); + +my %months = <Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec> Z=> 1..12; +my ($day, $mon, $yr) = $s.words; +printf '%d-%02d-%02d', $yr, %months{$mon}, $day.substr(0,*-2); diff --git a/challenge-347/feng-chang/raku/ch-2.raku b/challenge-347/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..ecb68db510 --- /dev/null +++ b/challenge-347/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s); + +my @s = $s.comb(/\d/); +print(|@s.splice(0,3), '-') while +@s > 4; +put do given +@s { + when 2|3 { @s.join } + when 4 { sprintf '%s%s-%s%s', |@s } +} diff --git a/challenge-347/feng-chang/raku/test.raku b/challenge-347/feng-chang/raku/test.raku new file mode 100755 index 0000000000..b1170f2d60 --- /dev/null +++ b/challenge-347/feng-chang/raku/test.raku @@ -0,0 +1,29 @@ +#!/bin/env raku + +# The Weekly Challenge 347 +use Test; + +sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) { + my ($expect, $assertion) = @input.splice(*-2, 2); + my $p = run $script, |@input, :out; + if $deeply { + is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion; + } else { + is $p.out.slurp(:close).chomp, $expect, $assertion; + } +} + +# Task 1, Format Date +pwc-test './ch-1.raku', '10th Nov 2025', '2025-11-10', 'Format Date: "10th Nov 2025" => 2025-11-10'; +pwc-test './ch-1.raku', '1st Jan 2025', '2025-01-01', 'Format Date: "1st Jan 2025" => 2025-01-01'; +pwc-test './ch-1.raku', '22nd Feb 2025', '2025-02-22', 'Format Date: "22nd Feb 2025" => 2025-02-22'; +pwc-test './ch-1.raku', '15th Apr 2025', '2025-04-15', 'Format Date: "15th Apr 2025" => 2025-04-15'; +pwc-test './ch-1.raku', '23rd Oct 2025', '2025-10-23', 'Format Date: "23rd Oct 2025" => 2025-10-23'; +pwc-test './ch-1.raku', '31st Dec 2025', '2025-12-31', 'Format Date: "31st Dec 2025" => 2025-12-31'; + +# Task 2, Format Phone Number +pwc-test './ch-2.raku', '1-23-45-6', '123-456', 'Format Phone Number: "1-23-45-6" => 123-456'; +pwc-test './ch-2.raku', '1234', '12-34', 'Format Phone Number: "1234" => 12-34'; +pwc-test './ch-2.raku', '12 345-6789', '123-456-789', 'Format Phone Number: "12 345-6789" => 123-456-789'; +pwc-test './ch-2.raku', '123 4567', '123-45-67', 'Format Phone Number: "123 4567" => 123-45-67'; +pwc-test './ch-2.raku', '123 456-78', '123-456-78', 'Format Phone Number: "123 456-78" => 123-456-78'; |
