aboutsummaryrefslogtreecommitdiff
path: root/challenge-235
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-09-24 18:15:37 +0100
committerGitHub <noreply@github.com>2023-09-24 18:15:37 +0100
commitcf9e5773c3e26f372aaf139c3345fad483ee7323 (patch)
tree3297c74159ecbbcaadfa54160a5fe5cb588def06 /challenge-235
parent64504b1cf4a49e53366aa14b597259311e711ade (diff)
parentb5814bbfadf26eed95700798af52e7427c9dee84 (diff)
downloadperlweeklychallenge-club-cf9e5773c3e26f372aaf139c3345fad483ee7323.tar.gz
perlweeklychallenge-club-cf9e5773c3e26f372aaf139c3345fad483ee7323.tar.bz2
perlweeklychallenge-club-cf9e5773c3e26f372aaf139c3345fad483ee7323.zip
Merge pull request #8756 from Solathian/branch-for-challenge-235
Added files!
Diffstat (limited to 'challenge-235')
-rw-r--r--challenge-235/solathian/perl/ch-1.pl36
-rw-r--r--challenge-235/solathian/perl/ch-2.pl23
2 files changed, 59 insertions, 0 deletions
diff --git a/challenge-235/solathian/perl/ch-1.pl b/challenge-235/solathian/perl/ch-1.pl
new file mode 100644
index 0000000000..db47138ab5
--- /dev/null
+++ b/challenge-235/solathian/perl/ch-1.pl
@@ -0,0 +1,36 @@
+#!usr/bin/perl
+use v5.38;
+
+use builtin 'indexed';
+use List::MoreUtils 'uniq';
+no warnings 'experimental';
+
+# Challenge 235 - 1 - Remove One
+# You are given an array of integers.
+# Write a script to find out if removing ONLY one integer makes it strictly increasing order.
+
+
+say rem1(0, 2, 9, 4, 6); # Output: true
+say rem1(5, 1, 3, 2); # Output: false
+say rem1(2, 2, 3); # Output: true
+say rem1(2, 2, 3, 4); # Output: true
+say rem1(2, 2, 3, 0); # Output: false since it is not strictly increasing
+
+
+sub rem1(@input)
+{
+
+ foreach my($index, $elem) ( indexed @input)
+ {
+ my @temp = @input;
+
+ splice(@temp, $index, 1);
+
+ my @sorted = uniq sort @temp; # somehow sort uniq is not working hmm (´。_。`)
+
+ return "true" if( "@sorted" eq "@temp");
+
+ }
+
+ return "false";
+} \ No newline at end of file
diff --git a/challenge-235/solathian/perl/ch-2.pl b/challenge-235/solathian/perl/ch-2.pl
new file mode 100644
index 0000000000..b816581db4
--- /dev/null
+++ b/challenge-235/solathian/perl/ch-2.pl
@@ -0,0 +1,23 @@
+#!usr/bin/perl
+use v5.38;
+
+# Challenge 235 - 2 - Duplicate Zeros
+
+dup0(1, 0, 2, 3, 0, 4, 5, 0); # (1, 0, 0, 2, 3, 0, 0, 4)
+dup0(1, 2, 3); # (1, 2, 3)
+dup0(0, 3, 0, 4, 5); # (0, 0, 3, 0, 0)
+
+
+sub dup0(@old)
+{
+
+ my @new;
+
+ foreach my $elem (@old)
+ {
+ push(@new, $elem);
+ push(@new, $elem) if($elem == 0);
+ }
+ splice(@new, @old); # remove elements after the size
+ say join ',', @new;
+} \ No newline at end of file