aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-275/paulo-custodio/Makefile2
-rw-r--r--challenge-275/paulo-custodio/perl/ch-1.pl40
-rw-r--r--challenge-275/paulo-custodio/perl/ch-2.pl47
-rw-r--r--challenge-275/paulo-custodio/t/test-1.yaml20
-rw-r--r--challenge-275/paulo-custodio/t/test-2.yaml20
5 files changed, 129 insertions, 0 deletions
diff --git a/challenge-275/paulo-custodio/Makefile b/challenge-275/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-275/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-275/paulo-custodio/perl/ch-1.pl b/challenge-275/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..b2180af349
--- /dev/null
+++ b/challenge-275/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+# Challenge 275
+#
+# Task 1: Broken Keys
+# Submitted by: Mohammad Sajid Anwar
+# You are given a sentence, $sentence and list of broken keys @keys.
+#
+# Write a script to find out how many words can be typed fully.
+#
+# Example 1
+# Input: $sentence = "Perl Weekly Challenge", @keys = ('l', 'a')
+# Output: 0
+# Example 2
+# Input: $sentence = "Perl and Raku", @keys = ('a')
+# Output: 1
+#
+# Only Perl since the other word two words contain 'a' and can't be typed fully.
+# Example 3
+# Input: $sentence = "Well done Team PWC", @keys = ('l', 'o')
+# Output: 2
+# Example 4
+# Input: $sentence = "The joys of polyglottism", @keys = ('T')
+# Output: 2
+
+use Modern::Perl;
+
+my($sentence, $keys) = split /,/, "@ARGV";
+my @words = split ' ', $sentence;
+my @keys = split ' ', $keys;
+
+say scalar grep {can_type($_, @keys)} @words;
+
+sub can_type {
+ my($word, @keys) = @_;
+ for my $ch (@keys) {
+ return 0 if $word =~ /$ch/i;
+ }
+ return 1;
+}
diff --git a/challenge-275/paulo-custodio/perl/ch-2.pl b/challenge-275/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..74ab1eca73
--- /dev/null
+++ b/challenge-275/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+
+# Challenge 275
+#
+# Task 2: Replace Digits
+# Submitted by: Mohammad Sajid Anwar
+# You are given an alphanumeric string, $str, where each character is either a
+# letter or a digit.
+#
+# Write a script to replace each digit in the given string with the value of the previous letter plus (digit) places.
+#
+# Example 1
+# Input: $str = 'a1c1e1'
+# Ouput: 'abcdef'
+#
+# shift('a', 1) => 'b'
+# shift('c', 1) => 'd'
+# shift('e', 1) => 'f'
+# Example 2
+# Input: $str = 'a1b2c3d4'
+# Output: 'abbdcfdh'
+#
+# shift('a', 1) => 'b'
+# shift('b', 2) => 'd'
+# shift('c', 3) => 'f'
+# shift('d', 4) => 'h'
+# Example 3
+# Input: $str = 'b2b'
+# Output: 'bdb'
+# Example 4
+# Input: $str = 'a16z'
+# Output: 'abgz'
+
+use Modern::Perl;
+
+$_ = shift // "";
+1 while s/([^\d])(\d+)/ expand($1, $2) /e;
+say $_;
+
+sub expand {
+ my($ch, $digits) = @_;
+ my $out = $ch;
+ for my $digit (split //, $digits) {
+ $out .= chr(ord($ch)+$digit);
+ }
+ return $out;
+}
diff --git a/challenge-275/paulo-custodio/t/test-1.yaml b/challenge-275/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..6f77cf02fa
--- /dev/null
+++ b/challenge-275/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,20 @@
+- setup:
+ cleanup:
+ args: Perl Weekly Challenge , l a
+ input:
+ output: 0
+- setup:
+ cleanup:
+ args: Perl and Raku , a
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: Well done Team PWC , l o
+ input:
+ output: 2
+- setup:
+ cleanup:
+ args: The joys of polyglottism , T
+ input:
+ output: 2
diff --git a/challenge-275/paulo-custodio/t/test-2.yaml b/challenge-275/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..8edb398e0b
--- /dev/null
+++ b/challenge-275/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,20 @@
+- setup:
+ cleanup:
+ args: a1c1e1
+ input:
+ output: abcdef
+- setup:
+ cleanup:
+ args: a1b2c3d4
+ input:
+ output: abbdcfdh
+- setup:
+ cleanup:
+ args: b2b
+ input:
+ output: bdb
+- setup:
+ cleanup:
+ args: a16z
+ input:
+ output: abgz