aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-264/paulo-custodio/Makefile2
-rw-r--r--challenge-264/paulo-custodio/perl/ch-1.pl38
-rw-r--r--challenge-264/paulo-custodio/perl/ch-2.pl51
-rw-r--r--challenge-264/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-264/paulo-custodio/t/test-2.yaml15
5 files changed, 121 insertions, 0 deletions
diff --git a/challenge-264/paulo-custodio/Makefile b/challenge-264/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-264/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-264/paulo-custodio/perl/ch-1.pl b/challenge-264/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..7bf856a74d
--- /dev/null
+++ b/challenge-264/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+# Challenge 264
+#
+# Task 1: Greatest English Letter
+# Submitted by: Mohammad Sajid Anwar
+# You are given a string, $str, made up of only alphabetic characters [a..zA..Z].
+#
+# Write a script to return the greatest english letter in the given string.
+#
+# A letter is greatest if it occurs as lower and upper case. Also letter ‘b’ is
+# greater than ‘a’ if ‘b’ appears after ‘a’ in the English alphabet.
+#
+# Example 1
+# Input: $str = 'PeRlwEeKLy'
+# Output: L
+#
+# There are two letters E and L that appears as lower and upper.
+# The letter L appears after E, so the L is the greatest english letter.
+# Example 2
+# Input: $str = 'ChaLlenge'
+# Output: L
+# Example 3
+# Input: $str = 'The'
+# Output: ''
+
+use Modern::Perl;
+
+say greatest_letter(shift // '');
+
+sub greatest_letter {
+ my($word) = @_;
+ for my $upper (reverse 'A' .. 'Z') {
+ my $lower = lc($upper);
+ return $upper if $word =~ /$upper/ && $word =~ /$lower/;
+ }
+ return "''";
+}
diff --git a/challenge-264/paulo-custodio/perl/ch-2.pl b/challenge-264/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..0a4a4ec9f8
--- /dev/null
+++ b/challenge-264/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+
+# Challenge 264
+#
+# Task 2: Target Array
+# Submitted by: Mohammad Sajid Anwar
+# You are given two arrays of integers, @source and @indices. The @indices can
+# only contains integers 0 <= i < size of @source.
+#
+# Write a script to create target array by insert at index $indices[i] the
+# value $source[i].
+#
+# Example 1
+# Input: @source = (0, 1, 2, 3, 4)
+# @indices = (0, 1, 2, 2, 1)
+# Output: (0, 4, 1, 3, 2)
+#
+# @source @indices @target
+# 0 0 (0)
+# 1 1 (0, 1)
+# 2 2 (0, 1, 2)
+# 3 2 (0, 1, 3, 2)
+# 4 1 (0, 4, 1, 3, 2)
+# Example 2
+# Input: @source = (1, 2, 3, 4, 0)
+# @indices = (0, 1, 2, 3, 0)
+# Output: (0, 1, 2, 3, 4)
+#
+# @source @indices @target
+# 1 0 (1)
+# 2 1 (1, 2)
+# 3 2 (1, 2, 3)
+# 4 3 (1, 2, 3, 4)
+# 0 0 (0, 1, 2, 3, 4)
+# Example 3
+# Input: @source = (1)
+# @indices = (0)
+# Output: (1)
+
+use Modern::Perl;
+
+my($source, $indices) = split /,/, "@ARGV";
+my @source = split ' ', $source;
+my @indices = split ' ', $indices;
+
+my @result;
+for (0 .. $#source) {
+ splice(@result, $indices[$_], 0, $source[$_]);
+}
+
+say "@result";
diff --git a/challenge-264/paulo-custodio/t/test-1.yaml b/challenge-264/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..f670be05a8
--- /dev/null
+++ b/challenge-264/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: PeRlwEeKLy
+ input:
+ output: L
+- setup:
+ cleanup:
+ args: ChaLlenge
+ input:
+ output: L
+- setup:
+ cleanup:
+ args: The
+ input:
+ output: "''"
diff --git a/challenge-264/paulo-custodio/t/test-2.yaml b/challenge-264/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..c3ccc99e99
--- /dev/null
+++ b/challenge-264/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 0 1 2 3 4 , 0 1 2 2 1
+ input:
+ output: 0 4 1 3 2
+- setup:
+ cleanup:
+ args: 1 2 3 4 0 , 0 1 2 3 0
+ input:
+ output: 0 1 2 3 4
+- setup:
+ cleanup:
+ args: 1 , 0
+ input:
+ output: 1