aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-02-27 19:09:58 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-02-27 19:09:58 +0800
commitd64db60d9dcf17d59060a03f5b1fbc5e82fc1953 (patch)
tree5a0102492b89828b4f4290b0cef15b99489eab3c
parent1b960b911528b5712dadb430638708c6211a2a9e (diff)
downloadperlweeklychallenge-club-d64db60d9dcf17d59060a03f5b1fbc5e82fc1953.tar.gz
perlweeklychallenge-club-d64db60d9dcf17d59060a03f5b1fbc5e82fc1953.tar.bz2
perlweeklychallenge-club-d64db60d9dcf17d59060a03f5b1fbc5e82fc1953.zip
challenge 258, raku solutions
-rwxr-xr-xchallenge-258/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-258/feng-chang/raku/ch-2.raku6
-rwxr-xr-xchallenge-258/feng-chang/raku/test.raku24
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-258/feng-chang/raku/ch-1.raku b/challenge-258/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..8b012ef76d
--- /dev/null
+++ b/challenge-258/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put +@ints.grep(*.chars %% 2);
diff --git a/challenge-258/feng-chang/raku/ch-2.raku b/challenge-258/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..14eea4eeb7
--- /dev/null
+++ b/challenge-258/feng-chang/raku/ch-2.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+my \k = @ints.pop;
+put @ints[(^+@ints).grep(*.base(2).comb.sum == k)].sum;
diff --git a/challenge-258/feng-chang/raku/test.raku b/challenge-258/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..fdfc671667
--- /dev/null
+++ b/challenge-258/feng-chang/raku/test.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+# The Weekly Challenge 258
+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, Count Even Digits Number
+pwc-test './ch-1.raku', <10 1 111 24 1000>, 3, 'Count Even Digits Number: 10, 1, 111, 24, 1000 => 3';
+pwc-test './ch-1.raku', <111 1 11111>, 0, 'Count Even Digits Number: 111, 1, 11111 => 0';
+pwc-test './ch-1.raku', <2 8 1024 256>, 1, 'Count Even Digits Number: 2, 8, 1024, 256 => 1';
+
+# Task 2, Sum of Values
+pwc-test './ch-2.raku', <2 5 9 11 3>, 1, 17, 'Sum of Values: @ints = (2, 5, 9, 11, 3), $k = 1 => 17';
+pwc-test './ch-2.raku', <2 5 9 11 3>, 2, 11, 'Sum of Values: @ints = (2, 5, 9, 11, 3), $k = 2 => 11';
+pwc-test './ch-2.raku', <2 5 9 11 3>, 0, 2, 'Sum of Values: @ints = (2, 5, 9, 11, 3), $k = 0 => 2';