aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-05-27 16:01:39 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-05-27 16:01:39 +0800
commit04b282d9f566e0508636a4c98d76a000a25818fd (patch)
tree485a334dbc1eb8119114d97f0cc79788e1370906
parent48269396c801f0ded00e6f812b6cba7e91279fd3 (diff)
downloadperlweeklychallenge-club-04b282d9f566e0508636a4c98d76a000a25818fd.tar.gz
perlweeklychallenge-club-04b282d9f566e0508636a4c98d76a000a25818fd.tar.bz2
perlweeklychallenge-club-04b282d9f566e0508636a4c98d76a000a25818fd.zip
challenge 271, raku solutions
-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)';