aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-01-08 17:15:58 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-01-08 17:15:58 +0800
commit3d1e9e4d3b3cf63602a48b74c600affdc28953b5 (patch)
tree17d637965a8b3253858f305f39427aa99fff7cc2
parentfc3d89a0bc6fa1f2dde93826dcd2c76dc0896c4f (diff)
downloadperlweeklychallenge-club-3d1e9e4d3b3cf63602a48b74c600affdc28953b5.tar.gz
perlweeklychallenge-club-3d1e9e4d3b3cf63602a48b74c600affdc28953b5.tar.bz2
perlweeklychallenge-club-3d1e9e4d3b3cf63602a48b74c600affdc28953b5.zip
challenge 250, raku solutions
-rwxr-xr-xchallenge-250/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-250/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-250/feng-chang/raku/test.raku25
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-250/feng-chang/raku/ch-1.raku b/challenge-250/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..3a94c9f361
--- /dev/null
+++ b/challenge-250/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+with @ints.pairs.map({ .key if .key % 10 == +.value }) { put +$_ ?? .min !! -1 };
diff --git a/challenge-250/feng-chang/raku/ch-2.raku b/challenge-250/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..40a946934c
--- /dev/null
+++ b/challenge-250/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@words);
+
+put @words.map({ m/^\d+$/ ?? +$_ !! .chars }).max;
diff --git a/challenge-250/feng-chang/raku/test.raku b/challenge-250/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..f6e6835403
--- /dev/null
+++ b/challenge-250/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 250
+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, Smallest Index
+pwc-test './ch-1.raku', |<0 1 2>, 0, 'Smallest Index: (0, 1, 2) => 0';
+pwc-test './ch-1.raku', |<4 3 2 1>, 2, 'Smallest Index: (4, 3, 2, 1) => 2';
+pwc-test './ch-1.raku', |<1 2 3 4 5 6 7 8 9 0>, -1, 'Smallest Index: (1, 2, 3, 4, 5, 6, 7, 8, 9, 0) => -1';
+
+# Task 2, Alphanumeric String Value
+pwc-test './ch-2.raku', |<perl 2 000 python r4ku>, 6, 'Alphanumeric String Value: ("perl", "2", "000", "python", "r4ku") => 6';
+pwc-test './ch-2.raku', |<001 1 000 0001>, 1, 'Alphanumeric String Value: ("001", "1", "000", "0001") => 1';
+
+done-testing;