aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-08-20 14:51:46 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-08-20 14:51:46 +0100
commit97dae0be98ef1a53b35e100afc62aabb35384726 (patch)
treece18a4aa37052da794955d40ee1b90c5e94f8d2a
parent3b01d861087c61577f5553751fcfca2fb105869f (diff)
downloadperlweeklychallenge-club-97dae0be98ef1a53b35e100afc62aabb35384726.tar.gz
perlweeklychallenge-club-97dae0be98ef1a53b35e100afc62aabb35384726.tar.bz2
perlweeklychallenge-club-97dae0be98ef1a53b35e100afc62aabb35384726.zip
Add Perl solution to challenge 235
-rw-r--r--challenge-235/paulo-custodio/Makefile2
-rw-r--r--challenge-235/paulo-custodio/perl/ch-1.pl51
-rw-r--r--challenge-235/paulo-custodio/perl/ch-2.pl44
-rw-r--r--challenge-235/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-235/paulo-custodio/t/test-2.yaml15
5 files changed, 127 insertions, 0 deletions
diff --git a/challenge-235/paulo-custodio/Makefile b/challenge-235/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-235/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-235/paulo-custodio/perl/ch-1.pl b/challenge-235/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..886aa2a188
--- /dev/null
+++ b/challenge-235/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+
+# Challenge 235
+#
+# Task 1: Remove One
+# Submitted by: Mohammad S Anwar
+#
+# You are given an array of integers.
+#
+# Write a script to find out if removing ONLY one integer makes it strictly
+# increasing order.
+# Example 1
+#
+# Input: @ints = (0, 2, 9, 4, 6)
+# Output: true
+#
+# Removing ONLY 9 in the given array makes it strictly increasing order.
+#
+# Example 2
+#
+# Input: @ints = (5, 1, 3, 2)
+# Output: false
+#
+# Example 3
+#
+# Input: @ints = (2, 2, 3)
+# Output: true
+
+use Modern::Perl;
+
+my @ints = @ARGV;
+
+say can_make_strict_increasing_order(@ints) ? "true" : "false";
+
+sub can_make_strict_increasing_order {
+ my(@ints) = @_;
+ return 1 if !@ints;
+ for my $i (0..$#ints) {
+ return 1 if is_strict_increasing(@ints[0..$i-1], @ints[$i+1..$#ints]);
+ }
+ return 0;
+}
+
+sub is_strict_increasing {
+ my(@ints) = @_;
+ return 1 if !@ints;
+ for my $i (1..$#ints) {
+ return 0 if $ints[$i] <= $ints[$i-1];
+ }
+ return 1;
+}
diff --git a/challenge-235/paulo-custodio/perl/ch-2.pl b/challenge-235/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..147b21b03b
--- /dev/null
+++ b/challenge-235/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+# Challenge 235
+#
+# Task 2: Duplicate Zeros
+# Submitted by: Mohammad S Anwar
+#
+# 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.
+# Example 1
+#
+# Input: @ints = (1, 0, 2, 3, 0, 4, 5, 0)
+# Ouput: (1, 0, 0, 2, 3, 0, 0, 4)
+#
+# Example 2
+#
+# Input: @ints = (1, 2, 3)
+# Ouput: (1, 2, 3)
+#
+# Example 3
+#
+# Input: @ints = (0, 3, 0, 4, 5)
+# Ouput: (0, 0, 3, 0, 0)
+
+use Modern::Perl;
+
+my @ints = @ARGV;
+say join " ", dup_zeros(@ints);
+
+sub dup_zeros {
+ my(@ints) = @_;
+ my @result;
+ for (@ints) {
+ if ($_==0) {
+ push @result, 0, 0;
+ }
+ else {
+ push @result, $_;
+ }
+ }
+ return @result[0..$#ints];
+}
diff --git a/challenge-235/paulo-custodio/t/test-1.yaml b/challenge-235/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..e33466a56d
--- /dev/null
+++ b/challenge-235/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 0 2 9 4 6
+ input:
+ output: true
+- setup:
+ cleanup:
+ args: 5 1 3 2
+ input:
+ output: false
+- setup:
+ cleanup:
+ args: 2 2 3
+ input:
+ output: true
diff --git a/challenge-235/paulo-custodio/t/test-2.yaml b/challenge-235/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..9e74df93de
--- /dev/null
+++ b/challenge-235/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 1 0 2 3 0 4 5 0
+ input:
+ output: 1 0 0 2 3 0 0 4
+- setup:
+ cleanup:
+ args: 1 2 3
+ input:
+ output: 1 2 3
+- setup:
+ cleanup:
+ args: 0 3 0 4 5
+ input:
+ output: 0 0 3 0 0