aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-03 14:52:30 +0100
committerGitHub <noreply@github.com>2020-10-03 14:52:30 +0100
commit299762198b2c0bb2525fb220a66de5f1a229fe2e (patch)
treec6bdd91ba3c25ed959e6fab0b6212ea157b0ab44
parentdf86e6274f452ee9b08f6e57be66f94459d83475 (diff)
parenta2065ef6658733188302184d0b845cab2a4781df (diff)
downloadperlweeklychallenge-club-299762198b2c0bb2525fb220a66de5f1a229fe2e.tar.gz
perlweeklychallenge-club-299762198b2c0bb2525fb220a66de5f1a229fe2e.tar.bz2
perlweeklychallenge-club-299762198b2c0bb2525fb220a66de5f1a229fe2e.zip
Merge pull request #2435 from wambash/challange-week-080
solutions week 080
-rwxr-xr-xchallenge-080/wambash/raku/ch-1.raku18
-rwxr-xr-xchallenge-080/wambash/raku/ch-2.raku31
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-080/wambash/raku/ch-1.raku b/challenge-080/wambash/raku/ch-1.raku
new file mode 100755
index 0000000000..78d26ca2ef
--- /dev/null
+++ b/challenge-080/wambash/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/env raku
+
+sub smallest-positive-number(+@n) {
+ 1..*
+ andthen .first: * == @n.none
+}
+
+multi MAIN (:$test!) {
+ use Test;
+ is smallest-positive-number(5, 2, -2, 0),1;
+ is smallest-positive-number(1, 8, -1),2;
+ is smallest-positive-number(2, 0, -1),1;
+ done-testing;
+}
+
+multi MAIN(**@n) {
+ say smallest-positive-number @n
+}
diff --git a/challenge-080/wambash/raku/ch-2.raku b/challenge-080/wambash/raku/ch-2.raku
new file mode 100755
index 0000000000..24a2d86948
--- /dev/null
+++ b/challenge-080/wambash/raku/ch-2.raku
@@ -0,0 +1,31 @@
+#!/usr/bin/env raku
+sub count-while ( @n, &f, Bool :$end ) {
+ $end ?? @n.reverse !! @n
+ andthen .map: { .&f || last }\
+ andthen .elems
+}
+
+sub count-candies ( +@n ) {
+ my @m = (@n Zcmp @n[1..*]);
+ @n.keys
+ andthen .map: {
+ @m[0 .. $_-1].&count-while( * eqv Less, :end )
+ max
+ @m[$_ .. *].&count-while( * eqv More )
+ }\
+ andthen .map: * + 1
+ andthen .sum
+}
+
+multi MAIN ( **@n ) {
+ say count-candies(@n)
+}
+
+multi MAIN ( :$test! ) {
+ use Test;
+ is count-candies(1, 4, 3, 2),(1,3,2,1).sum;
+ is count-candies(1, 2, 2), (1,2,1).sum;
+ is count-candies(11, 12, 22, 1, 2, 14, 3, 2, 1, -1), (1,2,3,1,2,5,4,3,2,1).sum;
+ is count-candies(<a b c e d>), (1,2,3,4,1).sum;
+ done-testing;
+}