aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-08-19 21:27:19 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-08-19 21:27:19 +0100
commitf36d66fb857f1ad05196e1af3f4b11818f3ad18f (patch)
tree7818162a22a19a64f39087a1eeecb5b251213145
parent1b3b6f5b57c35877bdd3af8d0aefbe045f3fa88d (diff)
downloadperlweeklychallenge-club-f36d66fb857f1ad05196e1af3f4b11818f3ad18f.tar.gz
perlweeklychallenge-club-f36d66fb857f1ad05196e1af3f4b11818f3ad18f.tar.bz2
perlweeklychallenge-club-f36d66fb857f1ad05196e1af3f4b11818f3ad18f.zip
Add Perl solution to challenge 231
-rw-r--r--challenge-231/paulo-custodio/Makefile2
-rw-r--r--challenge-231/paulo-custodio/perl/ch-1.pl40
-rw-r--r--challenge-231/paulo-custodio/perl/ch-2.pl30
-rw-r--r--challenge-231/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-231/paulo-custodio/t/test-2.yaml10
5 files changed, 97 insertions, 0 deletions
diff --git a/challenge-231/paulo-custodio/Makefile b/challenge-231/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-231/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-231/paulo-custodio/perl/ch-1.pl b/challenge-231/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..29ac80dbe6
--- /dev/null
+++ b/challenge-231/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+# Challenge 231
+#
+# Task 1: Min Max
+# Submitted by: Mohammad S Anwar
+# You are given an array of distinct integers.
+#
+# Write a script to find all elements that is neither minimum nor maximum.
+# Return -1 if you can’t.
+#
+# Example 1
+# Input: @ints = (3, 2, 1, 4)
+# Output: (3, 2)
+#
+# The minimum is 1 and maximum is 4 in the given array. So (3, 2) is neither
+# min nor max.
+# Example 2
+# Input: @ints = (3, 1)
+# Output: -1
+# Example 3
+# Input: @ints = (2, 1, 3)
+# Output: (2)
+#
+# The minimum is 1 and maximum is 3 in the given array. So 2 is neither
+# min nor max.
+
+use Modern::Perl;
+use List::Util 'min', 'max';
+
+say join " ", min_max(@ARGV);
+
+sub min_max {
+ my(@n) = @_;
+ my $min = min(@n);
+ my $max = max(@n);
+ my @ret = grep {$_ != $min && $_ != $max} @n;
+ return @ret ? @ret : -1;
+}
+
diff --git a/challenge-231/paulo-custodio/perl/ch-2.pl b/challenge-231/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..97f4099147
--- /dev/null
+++ b/challenge-231/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+# Challenge 231
+#
+# Task 2: Senior Citizens
+# Submitted by: Mohammad S Anwar
+# You are given a list of passenger details in the form “9999999999A1122”, where
+# 9 denotes the phone number, A the sex, 1 the age and 2 the seat number.
+#
+# Write a script to return the count of all senior citizens (age >= 60).
+#
+# Example 1
+# Input: @list = ("7868190130M7522","5303914400F9211","9273338290F4010")
+# Ouput: 2
+#
+# The age of the passengers in the given list are 75, 92 and 40.
+# So we have only 2 senior citizens.
+# Example 2
+# Input: @list = ("1313579440F2036","2921522980M5644")
+# Ouput: 0
+
+use Modern::Perl;
+
+say scalar grep {age($_) >= 60} @ARGV;
+
+sub age {
+ my($record) = @_;
+ my $age = 0+substr($record, 11, 2);
+ return $age;
+}
diff --git a/challenge-231/paulo-custodio/t/test-1.yaml b/challenge-231/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..3f4074e5a9
--- /dev/null
+++ b/challenge-231/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 3 2 1 4
+ input:
+ output: 3 2
+- setup:
+ cleanup:
+ args: 3 1
+ input:
+ output: -1
+- setup:
+ cleanup:
+ args: 2 1 3
+ input:
+ output: 2
diff --git a/challenge-231/paulo-custodio/t/test-2.yaml b/challenge-231/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..0892199703
--- /dev/null
+++ b/challenge-231/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: 7868190130M7522 5303914400F9211 9273338290F4010
+ input:
+ output: 2
+- setup:
+ cleanup:
+ args: 1313579440F2036 2921522980M5644
+ input:
+ output: 0