diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-08-19 22:58:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 22:58:52 +0100 |
| commit | 67d8d944ad8182df368110fec1f5dd4847c5efa0 (patch) | |
| tree | e02798ccd0847db426210dd6726f073e01d35108 | |
| parent | bb2e4e7d70550beff6c41a52fe5170571d2dd3d2 (diff) | |
| parent | f36d66fb857f1ad05196e1af3f4b11818f3ad18f (diff) | |
| download | perlweeklychallenge-club-67d8d944ad8182df368110fec1f5dd4847c5efa0.tar.gz perlweeklychallenge-club-67d8d944ad8182df368110fec1f5dd4847c5efa0.tar.bz2 perlweeklychallenge-club-67d8d944ad8182df368110fec1f5dd4847c5efa0.zip | |
Merge pull request #10665 from pauloscustodio/master
Add Perl solution to challenge 230
| -rw-r--r-- | challenge-230/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-230/paulo-custodio/perl/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-230/paulo-custodio/perl/ch-2.pl | 27 | ||||
| -rw-r--r-- | challenge-230/paulo-custodio/t/test-1.yaml | 10 | ||||
| -rw-r--r-- | challenge-230/paulo-custodio/t/test-2.yaml | 10 | ||||
| -rw-r--r-- | challenge-231/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-231/paulo-custodio/perl/ch-1.pl | 40 | ||||
| -rw-r--r-- | challenge-231/paulo-custodio/perl/ch-2.pl | 30 | ||||
| -rw-r--r-- | challenge-231/paulo-custodio/t/test-1.yaml | 15 | ||||
| -rw-r--r-- | challenge-231/paulo-custodio/t/test-2.yaml | 10 |
10 files changed, 169 insertions, 0 deletions
diff --git a/challenge-230/paulo-custodio/Makefile b/challenge-230/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-230/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-230/paulo-custodio/perl/ch-1.pl b/challenge-230/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..6c11615f84 --- /dev/null +++ b/challenge-230/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +# Challenge 230 +# +# Task 1: Separate Digits +# Submitted by: Mohammad S Anwar +# You are given an array of positive integers. +# +# Write a script to separate the given array into single digits. +# +# Example 1 +# Input: @ints = (1, 34, 5, 6) +# Output: (1, 3, 4, 5, 6) +# Example 2 +# Input: @ints = (1, 24, 51, 60) +# Output: (1, 2, 4, 5, 1, 6, 0) + +use Modern::Perl; +my @result; +for (@ARGV) { + push @result, split //, $_; +} +say "@result"; diff --git a/challenge-230/paulo-custodio/perl/ch-2.pl b/challenge-230/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..c4193a8eef --- /dev/null +++ b/challenge-230/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,27 @@ +#!/usr/bin/env perl + +# Challenge 230 +# +# Task 2: Count Words +# Submitted by: Mohammad S Anwar +# You are given an array of words made up of alphabetic characters and a prefix. +# +# Write a script to return the count of words that starts with the given prefix. +# +# Example 1 +# Input: @words = ("pay", "attention", "practice", "attend") +# $prefix = "at" +# Ouput: 2 +# +# Two words "attention" and "attend" starts with the given prefix "at". +# Example 2 +# Input: @words = ("janet", "julia", "java", "javascript") +# $prefix = "ja" +# Ouput: 3 +# +# Three words "janet", "java" and "javascripr" starts with the given prefix "ja". + +use Modern::Perl; + +my($prefix, @words) = @ARGV; +say scalar grep {/^$prefix/} @words; diff --git a/challenge-230/paulo-custodio/t/test-1.yaml b/challenge-230/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..4f6e9d427b --- /dev/null +++ b/challenge-230/paulo-custodio/t/test-1.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: 1 34 5 6 + input: + output: 1 3 4 5 6 +- setup: + cleanup: + args: 1 24 51 60 + input: + output: 1 2 4 5 1 6 0 diff --git a/challenge-230/paulo-custodio/t/test-2.yaml b/challenge-230/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..e5b270d997 --- /dev/null +++ b/challenge-230/paulo-custodio/t/test-2.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: at pay attention practice attend + input: + output: 2 +- setup: + cleanup: + args: ja janet julia java javascript + input: + output: 3 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 |
