diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2024-01-16 13:20:56 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2024-01-16 13:20:56 +0800 |
| commit | 34187d048c08cbbf3f3bf41770cd37921dbd39cf (patch) | |
| tree | b1cb4537d764c14d9c79595e40ad9c491195c513 | |
| parent | 8c4ac3f2dad1f1a186ae376589b74098cc219e16 (diff) | |
| download | perlweeklychallenge-club-34187d048c08cbbf3f3bf41770cd37921dbd39cf.tar.gz perlweeklychallenge-club-34187d048c08cbbf3f3bf41770cd37921dbd39cf.tar.bz2 perlweeklychallenge-club-34187d048c08cbbf3f3bf41770cd37921dbd39cf.zip | |
challenge 247, raku solutions
| -rwxr-xr-x | challenge-247/feng-chang/raku/ch-1.raku | 11 | ||||
| -rwxr-xr-x | challenge-247/feng-chang/raku/ch-2.raku | 6 | ||||
| -rwxr-xr-x | challenge-247/feng-chang/raku/test.raku | 20 |
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-247/feng-chang/raku/ch-1.raku b/challenge-247/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..bb82ac0754 --- /dev/null +++ b/challenge-247/feng-chang/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/bin/env raku + +unit sub MAIN(*@people); + +my %plan; +repeat { + %plan = @people Z=> @people.pick(*); +} until %plan.map({ family-name(.key) ne family-name(.value) }).all; +put "{.key.fmt('%-10s')} -> {.value}" for %plan; + +sub family-name(\name_) { name_.words.tail } diff --git a/challenge-247/feng-chang/raku/ch-2.raku b/challenge-247/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..facbb5867c --- /dev/null +++ b/challenge-247/feng-chang/raku/ch-2.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s); + +my %count = $s.comb.rotor(2 => -1).map(-> (\A,\B){ A~B if B.ord == A.ord + 1 }).Bag; +put %count.keys.sort({ -%count{$_}, $_ }).first; diff --git a/challenge-247/feng-chang/raku/test.raku b/challenge-247/feng-chang/raku/test.raku new file mode 100755 index 0000000000..94ad8695fc --- /dev/null +++ b/challenge-247/feng-chang/raku/test.raku @@ -0,0 +1,20 @@ +#!/bin/env raku + +# The Weekly Challenge 247 +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 2, Most Frequent Letter Pair +pwc-test './ch-2.raku', 'abcdbca', 'bc', 'Most Frequent Letter Pair: abcdbca => bc'; +pwc-test './ch-2.raku', 'cdeabeabfcdfabgcd', 'ab', 'Most Frequent Letter Pair: cdeabeabfcdfabgcd => ab'; + +done-testing; |
