aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shitov <mail@andreyshitov.com>2025-10-27 09:34:55 +0100
committerAndrew Shitov <mail@andreyshitov.com>2025-10-27 09:34:55 +0100
commit88f043a11896e9eb2f6fa999e7253de0a1d6ca3b (patch)
tree73f36fd65bcaeeb4521c007afd492d6bc3479914
parent01be821ef5ccd02011cad0d9927b873300bd6800 (diff)
downloadperlweeklychallenge-club-88f043a11896e9eb2f6fa999e7253de0a1d6ca3b.tar.gz
perlweeklychallenge-club-88f043a11896e9eb2f6fa999e7253de0a1d6ca3b.tar.bz2
perlweeklychallenge-club-88f043a11896e9eb2f6fa999e7253de0a1d6ca3b.zip
task 2
-rw-r--r--challenge-345/ash/raku/ch-2.raku34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-345/ash/raku/ch-2.raku b/challenge-345/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..86db3a5ded
--- /dev/null
+++ b/challenge-345/ash/raku/ch-2.raku
@@ -0,0 +1,34 @@
+# Task 2 of the Weekly Challenge 345
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-345/#TASK2
+
+say process 5, -1, -1; # 5 -1
+say process 3, 7, -1, -1, -1; # 7 3 -1
+say process 2, -1, 4, -1, -1; # 2 4 2
+say process 10, 20, -1, 30, -1, -1; # 20 30 20
+say process -1, -1, 5, -1; # -1 -1 5
+
+sub process(*@data) {
+ my @seen;
+ my @ans;
+
+ my $x = 0;
+
+ for @data -> $val {
+ if $val > 0 {
+ @seen.unshift($val);
+ $x = 0; # this was not clear from the task
+ }
+ elsif $val == -1 {
+ if $x < @seen.elems {
+ @ans.push(@seen[$x]);
+ }
+ else {
+ @ans.push(-1);
+ }
+
+ $x++;
+ }
+ }
+
+ return @ans;
+}