aboutsummaryrefslogtreecommitdiff
path: root/challenge-271
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-271')
-rwxr-xr-xchallenge-271/feng-chang/raku/ch-1.raku8
-rwxr-xr-xchallenge-271/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-271/feng-chang/raku/test.raku23
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-271/feng-chang/raku/ch-1.raku b/challenge-271/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..6cf9fe3068
--- /dev/null
+++ b/challenge-271/feng-chang/raku/ch-1.raku
@@ -0,0 +1,8 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s);
+
+use MONKEY-SEE-NO-EVAL;
+
+my @a = EVAL $s;
+put @a.map(+*.grep(1)).max(:k).min + 1;
diff --git a/challenge-271/feng-chang/raku/ch-2.raku b/challenge-271/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..14d32947d5
--- /dev/null
+++ b/challenge-271/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.sort({ .base(2).comb.sum, $_ });
diff --git a/challenge-271/feng-chang/raku/test.raku b/challenge-271/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..0f7552af9a
--- /dev/null
+++ b/challenge-271/feng-chang/raku/test.raku
@@ -0,0 +1,23 @@
+#!/bin/env raku
+
+# The Weekly Challenge 271
+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, Maximum Ones
+pwc-test './ch-1.raku', '[0,1],[1,0]', 1, 'Maximum Ones: [[0,1],[1,0]] => 1';
+pwc-test './ch-1.raku', '[0,0,0],[1,0,1]', 2, 'Maximum Ones: [[0,0,0],[1,0,1]] => 2';
+pwc-test './ch-1.raku', '[0,0],[1,1],[0,0]', 2, 'Maximum Ones: [[0,0],[1,1],[0,0]] => 2';
+
+# Task 2, Sort by 1 Bits
+pwc-test './ch-2.raku', <0 1 2 3 4 5 6 7 8>, '0 1 2 4 8 3 5 6 7', 'Sort by 1 Bits: @ints=(0,1,2,3,4,5,6,7,8) => (0,1,2,4,8,3,5,6,7)';
+pwc-test './ch-2.raku', <1024 512 256 128 64>, '64 128 256 512 1024', 'Sort by 1 Bits: @ints=(1024,512,256,128,64) => (64,128,256,512,1024)';