aboutsummaryrefslogtreecommitdiff
path: root/challenge-235
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-09-21 10:53:00 +0100
committerGitHub <noreply@github.com>2023-09-21 10:53:00 +0100
commit848719460463783ac2d6a99e07f92f9ff70ff884 (patch)
tree456c682df13461b773e125d5a9a4421d93684888 /challenge-235
parent277b86e1f3281ff52f8fb47d335ff76a90d09ab7 (diff)
parenta0c5587b084722a8b538a4f50defc12ea757f6b0 (diff)
downloadperlweeklychallenge-club-848719460463783ac2d6a99e07f92f9ff70ff884.tar.gz
perlweeklychallenge-club-848719460463783ac2d6a99e07f92f9ff70ff884.tar.bz2
perlweeklychallenge-club-848719460463783ac2d6a99e07f92f9ff70ff884.zip
Merge pull request #8743 from rcmlz/ch-235
solution w235
Diffstat (limited to 'challenge-235')
-rw-r--r--challenge-235/rcmlz/raku/task-one.rakumod40
-rw-r--r--challenge-235/rcmlz/raku/task-two.rakumod28
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-235/rcmlz/raku/task-one.rakumod b/challenge-235/rcmlz/raku/task-one.rakumod
new file mode 100644
index 0000000000..47a86d51af
--- /dev/null
+++ b/challenge-235/rcmlz/raku/task-one.rakumod
@@ -0,0 +1,40 @@
+unit module rcmlz::raku::task-one:ver<0.0.1>:auth<rcmlz@github.com)>;
+
+# run in terminal: raku --optimize=3 -I challenge-nr235/rcmlz/raku/ -- test/challenge-nr235/raku/task-one.rakutest
+# or raku --optimize=3 -I challenge-nr235 -- test/benchmark-scalabiity.raku --task=task-one --user=rcmlz --max-run-times=1,3,7 --test-before-benchmark=True --out-folder=/tmp nr235; cat /tmp/nr235_task-one.csv
+
+my $REPLACEMENTS = 1;
+
+#|[
+You are given an array of integers.
+
+- Write a script to find out if removing ONLY one integer makes it strictly increasing order.
+]
+our proto solution(@input, $replacements=$REPLACEMENTS) is export {*}
+
+multi solution(@input where @input.unique.elems < @input.elems - 1, $replacements=$REPLACEMENTS){ False }
+
+multi solution(@input where @input.elems < 2, $replacements=$REPLACEMENTS){ True }
+
+multi solution(@input where @input.elems == 2, $replacements=$REPLACEMENTS){
+ $replacements || @input[0] < @input[1] ?? True !! False
+}
+
+multi solution(@input, $replacements=$REPLACEMENTS) {
+ for 1..^@input.elems -> $i {
+
+ if @input[$i - 1] >= @input[$i] {
+
+ return False if $replacements < 1;
+
+ my @part1 = @input.clone;
+ my @part2 = @input.clone;
+
+ @part1.splice($i,1);
+ @part2.splice($i - 1,1);
+
+ return samewith(@part1, $replacements - 1) || samewith(@part2, $replacements - 1);
+ }
+ }
+ return True
+} \ No newline at end of file
diff --git a/challenge-235/rcmlz/raku/task-two.rakumod b/challenge-235/rcmlz/raku/task-two.rakumod
new file mode 100644
index 0000000000..3750455a0c
--- /dev/null
+++ b/challenge-235/rcmlz/raku/task-two.rakumod
@@ -0,0 +1,28 @@
+unit module rcmlz::raku::task-two:ver<0.0.1>:auth<rcmlz@github.com)>;
+
+# run in terminal: raku --optimize=3 -I challenge-nr235/rcmlz/raku/ -- test/challenge-nr235/raku/task-two.rakutest
+# or raku --optimize=3 -I challenge-nr235 -- test/benchmark-scalabiity.raku --task=task-two --user=rcmlz --max-run-times=1,3,7 --test-before-benchmark=True --out-folder=/tmp nr235; cat /tmp/nr235_task-two.csv
+
+#|[
+You are given an array of integers.
+
+Write a script to duplicate each occurrence of ZERO in the given array
+and shift the remaining to the right but make sure the size of array remain the same.
+]
+our sub solution(@input) is export {
+ my $n = @input.elems;
+ my @output;
+ for @input -> $entry {
+ if $entry == 0 {
+ for ^(min($n, 2)) {
+ @output.push: 0;
+ $n--;
+ }
+ }else{
+ @output.push: $entry;
+ $n--;
+ }
+ last if $n < 1;
+ }
+ return @output.List
+} \ No newline at end of file