diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-13 13:14:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-13 13:14:42 +0100 |
| commit | c3a1d8ae574ba0d5f9a407e83205160bac841046 (patch) | |
| tree | 427f725642078f32164487ccf5fb63107f080738 | |
| parent | 52f672b168abfa013421024f26e3175eb3994660 (diff) | |
| parent | 05ceb9d207de2c82a60ada545921b9cee27327a8 (diff) | |
| download | perlweeklychallenge-club-c3a1d8ae574ba0d5f9a407e83205160bac841046.tar.gz perlweeklychallenge-club-c3a1d8ae574ba0d5f9a407e83205160bac841046.tar.bz2 perlweeklychallenge-club-c3a1d8ae574ba0d5f9a407e83205160bac841046.zip | |
Merge pull request #12010 from seaker/master
challenge 321, raku solutions
| -rwxr-xr-x | challenge-321/feng-chang/raku/ch-1.raku | 6 | ||||
| -rwxr-xr-x | challenge-321/feng-chang/raku/ch-2.raku | 10 | ||||
| -rwxr-xr-x | challenge-321/feng-chang/raku/test.raku | 24 |
3 files changed, 40 insertions, 0 deletions
diff --git a/challenge-321/feng-chang/raku/ch-1.raku b/challenge-321/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..e2fd2c80f2 --- /dev/null +++ b/challenge-321/feng-chang/raku/ch-1.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(*@ints where +* %% 2); + +@ints = +«@ints.sort; +put +(gather { take (@ints.shift + @ints.pop) / 2 while +@ints }).unique; diff --git a/challenge-321/feng-chang/raku/ch-2.raku b/challenge-321/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..cbaf1c4b3a --- /dev/null +++ b/challenge-321/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s1, Str:D $s2); + +put redact($s1) eq redact($s2); + +sub redact(Str:D $s is copy --> Str:D) { + $s .= subst(/. '#'/) while $s.contains('#'); + $s +} diff --git a/challenge-321/feng-chang/raku/test.raku b/challenge-321/feng-chang/raku/test.raku new file mode 100755 index 0000000000..4343f0a84c --- /dev/null +++ b/challenge-321/feng-chang/raku/test.raku @@ -0,0 +1,24 @@ +#!/bin/env raku + +# The Weekly Challenge 321 +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, Distinct Average +pwc-test './ch-1.raku', <1 2 4 3 5 6>, 1, 'Distinct Average: (1,2,4,3,5,6) => 1'; +pwc-test './ch-1.raku', <0 2 4 8 3 5>, 2, 'Distinct Average: (0,2,4,8,3,5) => 2'; +pwc-test './ch-1.raku', <7 3 1 0 5 9>, 2, 'Distinct Average: (7,3,1,0,5,9) => 2'; + +# Task 2, Backspace Compare +pwc-test './ch-2.raku', <ab#c ad#c>, 'True', 'Backspace Compare: <ab*c ad*c> => true'; +pwc-test './ch-2.raku', <ab## a#b#>, 'True', 'Backspace Compare: <ab** a*b*> => true'; +pwc-test './ch-2.raku', <a#b c>, 'False', 'Backspace Compare: <a*b c> => false'; |
