diff options
| -rw-r--r-- | challenge-273/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-273/paulo-custodio/perl/ch-1.pl | 39 | ||||
| -rw-r--r-- | challenge-273/paulo-custodio/perl/ch-2.pl | 28 | ||||
| -rw-r--r-- | challenge-273/paulo-custodio/t/test-1.yaml | 30 | ||||
| -rw-r--r-- | challenge-273/paulo-custodio/t/test-2.yaml | 20 |
5 files changed, 119 insertions, 0 deletions
diff --git a/challenge-273/paulo-custodio/Makefile b/challenge-273/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-273/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-273/paulo-custodio/perl/ch-1.pl b/challenge-273/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..c46e80c366 --- /dev/null +++ b/challenge-273/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,39 @@ +#!/usr/bin/env perl + +# Challenge 273 +# +# Task 1: Percentage of Character +# Submitted by: Mohammad Sajid Anwar +# You are given a string, $str and a character $char. +# +# Write a script to return the percentage, nearest whole, of given character in +# the given string. +# +# Example 1 +# Input: $str = "perl", $char = "e" +# Output: 25 +# Example 2 +# Input: $str = "java", $char = "a" +# Output: 50 +# Example 3 +# Input: $str = "python", $char = "m" +# Output: 0 +# Example 4 +# Input: $str = "ada", $char = "a" +# Output: 67 +# Example 5 +# Input: $str = "ballerina", $char = "l" +# Output: 22 +# Example 6 +# Input: $str = "analitik", $char = "k" +# Output: 13 + +use Modern::Perl; + +say percent_char(@ARGV); + +sub percent_char { + my($str, $ch) = @_; + my $percent = 100 * ($str =~ s/$ch/$ch/g) / length($str); + return int($percent+0.5); +} diff --git a/challenge-273/paulo-custodio/perl/ch-2.pl b/challenge-273/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..a21c7db279 --- /dev/null +++ b/challenge-273/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +# Challenge 273 +# +# Task 2: B After A +# Submitted by: Mohammad Sajid Anwar +# You are given a string, $str. +# +# Write a script to return true if there is at least one b, and no a appears +# after the first b. +# +# Example 1 +# Input: $str = "aabb" +# Output: true +# Example 2 +# Input: $str = "abab" +# Output: false +# Example 3 +# Input: $str = "aaa" +# Output: false +# Example 4 +# Input: $str = "bbb" +# Output: true + +use Modern::Perl; + +$_ = shift // ""; +say /b/ && !/^[^b]*b.*?a/ ? 'true' : 'false'; diff --git a/challenge-273/paulo-custodio/t/test-1.yaml b/challenge-273/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..756e9f80b7 --- /dev/null +++ b/challenge-273/paulo-custodio/t/test-1.yaml @@ -0,0 +1,30 @@ +- setup: + cleanup: + args: perl e + input: + output: 25 +- setup: + cleanup: + args: java a + input: + output: 50 +- setup: + cleanup: + args: python m + input: + output: 0 +- setup: + cleanup: + args: ada a + input: + output: 67 +- setup: + cleanup: + args: ballerina l + input: + output: 22 +- setup: + cleanup: + args: analitik k + input: + output: 13 diff --git a/challenge-273/paulo-custodio/t/test-2.yaml b/challenge-273/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..a114fccb37 --- /dev/null +++ b/challenge-273/paulo-custodio/t/test-2.yaml @@ -0,0 +1,20 @@ +- setup: + cleanup: + args: aabb + input: + output: true +- setup: + cleanup: + args: abab + input: + output: false +- setup: + cleanup: + args: aaa + input: + output: false +- setup: + cleanup: + args: bbb + input: + output: true |
