aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-06-10 09:23:53 +0100
committerGitHub <noreply@github.com>2025-06-10 09:23:53 +0100
commitffd290826e81ecea3886cc029be6187d9defb222 (patch)
tree5f32cfe238efea323fac3071000fddc11d893a93
parent7ad8fdb1ba3d67e7d46ff5ed9527c200ab5dbc0e (diff)
parentee0fa13bfdb37b173c13736fa512b46e2b688317 (diff)
downloadperlweeklychallenge-club-ffd290826e81ecea3886cc029be6187d9defb222.tar.gz
perlweeklychallenge-club-ffd290826e81ecea3886cc029be6187d9defb222.tar.bz2
perlweeklychallenge-club-ffd290826e81ecea3886cc029be6187d9defb222.zip
Merge pull request #12160 from seaker/master
challenge 325, raku solutions
-rwxr-xr-xchallenge-325/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-325/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-325/feng-chang/raku/test.raku24
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-325/feng-chang/raku/ch-1.raku b/challenge-325/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..2dfccec118
--- /dev/null
+++ b/challenge-325/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s where *.comb».Int.all == 0|1);
+
+put (0, |$s.match(/'1'+/, :g).map(*.chars)).max;
diff --git a/challenge-325/feng-chang/raku/ch-2.raku b/challenge-325/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..59f18ae835
--- /dev/null
+++ b/challenge-325/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put (^+@ints).map({ @ints[$_] - (@ints.tail(*-$_-1).first(*≤@ints[$_]) // 0) });
diff --git a/challenge-325/feng-chang/raku/test.raku b/challenge-325/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..270203cb9e
--- /dev/null
+++ b/challenge-325/feng-chang/raku/test.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+# The Weekly Challenge 325
+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, Consecutive One
+pwc-test './ch-1.raku', '0110111', 3, 'Consecutive One: 0110111 => 3';
+pwc-test './ch-1.raku', '0000', 0, 'Consecutive One: 0000 => 0';
+pwc-test './ch-1.raku', '101011', 2, 'Consecutive One: 101011 => 2';
+
+# Task 2, Final Price
+pwc-test './ch-2.raku', <8 4 6 2 3>, '4 2 4 2 3', 'Final Price: 8,4,6,2,3 => 4,2,4,2,3';
+pwc-test './ch-2.raku', <1 2 3 4 5>, '1 2 3 4 5', 'Final Price: 1,2,3,4,5 => 1,2,3,4,5';
+pwc-test './ch-2.raku', <7 1 1 5>, '6 0 1 5', 'Final Price: 7,1,1,5 => 6,0,1,5';