diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-08-19 21:10:57 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-08-19 21:10:57 +0100 |
| commit | 1b3b6f5b57c35877bdd3af8d0aefbe045f3fa88d (patch) | |
| tree | e920b4b35f5e5c0a30493a5f777b1a90b804af76 | |
| parent | e05fac705999006a4443829cb18acca756add415 (diff) | |
| download | perlweeklychallenge-club-1b3b6f5b57c35877bdd3af8d0aefbe045f3fa88d.tar.gz perlweeklychallenge-club-1b3b6f5b57c35877bdd3af8d0aefbe045f3fa88d.tar.bz2 perlweeklychallenge-club-1b3b6f5b57c35877bdd3af8d0aefbe045f3fa88d.zip | |
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 |
5 files changed, 72 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 |
