aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-180/paulo-custodio/Makefile2
-rw-r--r--challenge-180/paulo-custodio/perl/ch-1.pl28
-rw-r--r--challenge-180/paulo-custodio/perl/ch-2.pl27
-rw-r--r--challenge-180/paulo-custodio/t/test-1.yaml10
-rw-r--r--challenge-180/paulo-custodio/t/test-2.yaml10
5 files changed, 77 insertions, 0 deletions
diff --git a/challenge-180/paulo-custodio/Makefile b/challenge-180/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-180/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-180/paulo-custodio/perl/ch-1.pl b/challenge-180/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..1a5c0c89e5
--- /dev/null
+++ b/challenge-180/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+# Challenge 180
+#
+# Task 1: First Unique Character
+# Submitted by: Mohammad S Anwar
+#
+# You are given a string, $s.
+#
+# Write a script to find out the first unique character in the given string and
+# print its index (0-based).
+# Example 1
+#
+# Input: $s = "Perl Weekly Challenge"
+# Output: 0 as 'P' is the first unique character
+#
+# Example 2
+#
+# Input: $s = "Long Live Perl"
+# Output: 1 as 'o' is the first unique character
+
+use Modern::Perl;
+
+my @chars = split //, "@ARGV";
+my %count; $count{$_}++ for @chars;
+my $pos = (map {$_->[0]} grep {$_->[1] == 1} map {[$_, $count{$chars[$_]}]}
+ 0..$#chars)[0];
+say $pos;
diff --git a/challenge-180/paulo-custodio/perl/ch-2.pl b/challenge-180/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..e8a8888b7a
--- /dev/null
+++ b/challenge-180/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# Challenge 180
+#
+# Task 2: Trim List
+# Submitted by: Mohammad S Anwar
+#
+# You are given list of numbers, @n and an integer $i.
+#
+# Write a script to trim the given list where element is less than or equal to
+# the given integer.
+# Example 1
+#
+# Input: @n = (1,4,2,3,5) and $i = 3
+# Output: (4,5)
+#
+# Example 2
+#
+# Input: @n = (9,0,6,2,3,8,5) and $i = 4
+# Output: (9,6,8,5)
+
+use Modern::Perl;
+
+@ARGV>2 or die "usage: ch-2.pl list... i\n";
+my @list = @ARGV;
+my $i = pop(@list);
+say join ", ", grep {$_ > $i} @list;
diff --git a/challenge-180/paulo-custodio/t/test-1.yaml b/challenge-180/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..5aa4889028
--- /dev/null
+++ b/challenge-180/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: Perl Weekly Challenge
+ input:
+ output: 0
+- setup:
+ cleanup:
+ args: Long Live Perl
+ input:
+ output: 1
diff --git a/challenge-180/paulo-custodio/t/test-2.yaml b/challenge-180/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..cdbecff2bc
--- /dev/null
+++ b/challenge-180/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: 1 4 2 3 5 3
+ input:
+ output: 4, 5
+- setup:
+ cleanup:
+ args: 9 0 6 2 3 8 5 4
+ input:
+ output: 9, 6, 8, 5