diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-10-16 17:26:20 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-10-16 17:26:20 +0800 |
| commit | f1bd3bd0a86630b6d6446edc68ff5035980bec0f (patch) | |
| tree | 81fd9861140c769a92be3c43ef5c564161aaf2a2 | |
| parent | 50febb3c84c6adc42c33005f8f85ae229ddde328 (diff) | |
| download | perlweeklychallenge-club-f1bd3bd0a86630b6d6446edc68ff5035980bec0f.tar.gz perlweeklychallenge-club-f1bd3bd0a86630b6d6446edc68ff5035980bec0f.tar.bz2 perlweeklychallenge-club-f1bd3bd0a86630b6d6446edc68ff5035980bec0f.zip | |
challenge 239, raku solutions
| -rwxr-xr-x | challenge-239/feng-chang/raku/ch-1.raku | 8 | ||||
| -rwxr-xr-x | challenge-239/feng-chang/raku/ch-2.raku | 6 | ||||
| -rwxr-xr-x | challenge-239/feng-chang/raku/test.raku | 29 |
3 files changed, 43 insertions, 0 deletions
diff --git a/challenge-239/feng-chang/raku/ch-1.raku b/challenge-239/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..e31035cccc --- /dev/null +++ b/challenge-239/feng-chang/raku/ch-1.raku @@ -0,0 +1,8 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s1, Str:D $s2); + +my @arr1 = $s1.words; +my @arr2 = $s2.words; + +put @arr1.join eq @arr2.join; diff --git a/challenge-239/feng-chang/raku/ch-2.raku b/challenge-239/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..968b279449 --- /dev/null +++ b/challenge-239/feng-chang/raku/ch-2.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(*@strs); + +my %allowed = @strs.pop.comb.Set; +put +@strs.grep(*.comb.Set (<=) %allowed); diff --git a/challenge-239/feng-chang/raku/test.raku b/challenge-239/feng-chang/raku/test.raku new file mode 100755 index 0000000000..17f67ce8cb --- /dev/null +++ b/challenge-239/feng-chang/raku/test.raku @@ -0,0 +1,29 @@ +#!/bin/env raku + +# The Weekly Challenge 239 +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, Same String +pwc-test './ch-1.raku', 'ab c', 'a bc', 'True', 'Same String: "ab c", "a bc" => True'; +pwc-test './ch-1.raku', 'ab c', 'ac b', 'False', 'Same String: "ab c", "ac b" => False'; +pwc-test './ch-1.raku', 'ab cd e', 'abcde', 'True', 'Same String: "ab cd e", "abcde" => True'; + +# Task 2, Consistent Strings +pwc-test './ch-2.raku', |<ad bd aaab baa badab ab>, 2, + 'Consistent Strings: @str = ("ad", "bd", "aaab", "baa", "badab"), $allowed = "ab" => 2'; +pwc-test './ch-2.raku', |<a b c ab ac bc abc abc>, 7, + 'Consistent Strings: @str = ("a", "b", "c", "ab", "ac", "bc", "abc"), $allowed = "abc" => 7'; +pwc-test './ch-2.raku', |<cc acd b ba bac bad ac d cad>, 4, + 'Consistent Strings: @str = ("cc", "acd", "b", "ba", "bac", "bad", "ac", "d"), $allowed = "cad" => 4'; + +done-testing; |
