diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-08-14 10:34:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-14 10:34:24 +0100 |
| commit | 7063d2b2c55384f78c85f48146bd0a33bcea001f (patch) | |
| tree | 4376cb282925d71067ae214c60a3948f57ce3973 | |
| parent | 7ba825fa35167322bdcd7436fa15b8d2d67515ac (diff) | |
| parent | f6670f0ff9e0cf8b313bdf153a298535476c0c2e (diff) | |
| download | perlweeklychallenge-club-7063d2b2c55384f78c85f48146bd0a33bcea001f.tar.gz perlweeklychallenge-club-7063d2b2c55384f78c85f48146bd0a33bcea001f.tar.bz2 perlweeklychallenge-club-7063d2b2c55384f78c85f48146bd0a33bcea001f.zip | |
Merge pull request #10613 from pauloscustodio/master
Add Perl solution to challenge 280
| -rw-r--r-- | challenge-280/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-280/paulo-custodio/perl/ch-1.pl | 34 | ||||
| -rw-r--r-- | challenge-280/paulo-custodio/perl/ch-2.pl | 32 | ||||
| -rw-r--r-- | challenge-280/paulo-custodio/t/test-1.yaml | 15 | ||||
| -rw-r--r-- | challenge-280/paulo-custodio/t/test-2.yaml | 15 |
5 files changed, 98 insertions, 0 deletions
diff --git a/challenge-280/paulo-custodio/Makefile b/challenge-280/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-280/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-280/paulo-custodio/perl/ch-1.pl b/challenge-280/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..bae783b821 --- /dev/null +++ b/challenge-280/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +# Challenge 280 +# +# Task 1: Twice Appearance +# Submitted by: Mohammad Sajid Anwar +# You are given a string, $str, containing lowercase English letters only. +# +# Write a script to print the first letter that appears twice. +# +# Example 1 +# Input: $str = "acbddbca" +# Output: "d" +# Example 2 +# Input: $str = "abccd" +# Output: "c" +# Example 3 +# Input: $str = "abcdabbb" +# Output: "a" + +use Modern::Perl; + +my $str = shift || ""; +say double_letter($str); + +sub double_letter { + my($str) = @_; + + my %found; + for (split //, $str) { + return $_ if $found{$_}++; + } + return ""; +} diff --git a/challenge-280/paulo-custodio/perl/ch-2.pl b/challenge-280/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..a09904d437 --- /dev/null +++ b/challenge-280/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +# Challenge 280 +# +# Task 2: Count Asterisks +# Submitted by: Mohammad Sajid Anwar +# You are given a string, $str, where every two consecutive vertical bars are +# grouped into a pair. +# +# Write a script to return the number of asterisks, *, excluding any between +# each pair of vertical bars. +# +# Example 1 +# Input: $str = "p|*e*rl|w**e|*ekly|" +# Ouput: 2 +# +# The characters we are looking here are "p" and "w**e". +# Example 2 +# Input: $str = "perl" +# Ouput: 0 +# Example 3 +# Input: $str = "th|ewe|e**|k|l***ych|alleng|e" +# Ouput: 5 +# +# The characters we are looking here are "th", "e**", "l***ych" and "e". + +use Modern::Perl; + +my $str = shift // ""; +$str =~ s/\|[^|]*\|//g; +my $count = $str =~ tr/*/*/; +say $count; diff --git a/challenge-280/paulo-custodio/t/test-1.yaml b/challenge-280/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..f4d353757e --- /dev/null +++ b/challenge-280/paulo-custodio/t/test-1.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: acbddbca + input: + output: d +- setup: + cleanup: + args: abccd + input: + output: c +- setup: + cleanup: + args: abcdabbb + input: + output: a diff --git a/challenge-280/paulo-custodio/t/test-2.yaml b/challenge-280/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..58c30615f7 --- /dev/null +++ b/challenge-280/paulo-custodio/t/test-2.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: "'p|*e*rl|w**e|*ekly|'" + input: + output: 2 +- setup: + cleanup: + args: "'perl'" + input: + output: 0 +- setup: + cleanup: + args: "'th|ewe|e**|k|l***ych|alleng|e'" + input: + output: 5 |
