diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-03-14 17:54:37 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-03-14 17:54:37 +0800 |
| commit | f0932f64660f5f3ea94798d22731f6710104fd5a (patch) | |
| tree | caa6f4813dbe8ca03c96ca5e1cdcf53e75044d9c /challenge-208/feng-chang | |
| parent | e43a0f1d5587d6e65a081f83c89de2ef79ea9b35 (diff) | |
| download | perlweeklychallenge-club-f0932f64660f5f3ea94798d22731f6710104fd5a.tar.gz perlweeklychallenge-club-f0932f64660f5f3ea94798d22731f6710104fd5a.tar.bz2 perlweeklychallenge-club-f0932f64660f5f3ea94798d22731f6710104fd5a.zip | |
Challenge 208, Raku solutions
Diffstat (limited to 'challenge-208/feng-chang')
| -rwxr-xr-x | challenge-208/feng-chang/raku/ch-1.raku | 24 | ||||
| -rwxr-xr-x | challenge-208/feng-chang/raku/ch-2.raku | 6 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-208/feng-chang/raku/ch-1.raku b/challenge-208/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..5d36026336 --- /dev/null +++ b/challenge-208/feng-chang/raku/ch-1.raku @@ -0,0 +1,24 @@ +#!/bin/env raku + +sub min-index-sum(@list1, @list2) { + my %hash1 = @list1 Z=> ^+@list1; + my %hash2 = @list2 Z=> ^+@list2; + my @common = (%hash1.keys (&) %hash2.keys).keys; + my $min-index = @common.map({ %hash1{$_} + %hash2{$_} }).min; + + @common.grep({ %hash1{$_} + %hash2{$_} == $min-index }).sort +} + +multi MAIN('test') { + use Test; + + is-deeply min-index-sum(<Perl Raku Love>, <Raku Perl Hate>), <Perl Raku>, 'example 1 matches'; + is-deeply min-index-sum(<A B C>, <D E F>), < >, 'example 2 matches'; + is-deeply min-index-sum(<A B C>, <C A B>), ('A',), 'example 3 matches'; + + done-testing; +} + +multi MAIN() { + put min-index-sum(|$*IN.lines[0, 1].map({ .words.Array })); +} diff --git a/challenge-208/feng-chang/raku/ch-2.raku b/challenge-208/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..5d85033739 --- /dev/null +++ b/challenge-208/feng-chang/raku/ch-2.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(*@N); + +put "Duplicate: { @N.Bag.grep({ .value > 1 }).Hash.keys || 'null' } and ", + "Missing: { ((@N[0] .. +@N) (-) @N».Int) || 'null' }"; |
