aboutsummaryrefslogtreecommitdiff
path: root/challenge-282
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-08-13 14:22:35 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-08-13 14:22:35 +0100
commitb6dc2aa7006eca57c2ee33c39f1b53b52b6b9d75 (patch)
tree7d16aa7a6a98f8cd625abf991589ab6e067e64b9 /challenge-282
parent24714dd7bce72d04f7e4c3c7233d10eb6b25ab0b (diff)
downloadperlweeklychallenge-club-b6dc2aa7006eca57c2ee33c39f1b53b52b6b9d75.tar.gz
perlweeklychallenge-club-b6dc2aa7006eca57c2ee33c39f1b53b52b6b9d75.tar.bz2
perlweeklychallenge-club-b6dc2aa7006eca57c2ee33c39f1b53b52b6b9d75.zip
Add perl solution to challenge 282
Diffstat (limited to 'challenge-282')
-rw-r--r--challenge-282/paulo-custodio/Makefile2
-rw-r--r--challenge-282/paulo-custodio/perl/ch-1.pl39
-rw-r--r--challenge-282/paulo-custodio/perl/ch-2.pl43
-rw-r--r--challenge-282/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-282/paulo-custodio/t/test-2.yaml15
5 files changed, 114 insertions, 0 deletions
diff --git a/challenge-282/paulo-custodio/Makefile b/challenge-282/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-282/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-282/paulo-custodio/perl/ch-1.pl b/challenge-282/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..739c9c0216
--- /dev/null
+++ b/challenge-282/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+# Challenge 282
+#
+# Task 1: Good Integer
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given a positive integer, $int, having 3 or more digits.
+#
+# Write a script to return the Good Integer in the given integer or -1 if none found.
+#
+# A good integer is exactly three consecutive matching digits.
+#
+# Example 1
+#
+# Input: $int = 12344456
+# Output: 444
+#
+# Example 2
+#
+# Input: $int = 1233334
+# Output: -1
+#
+# Example 3
+#
+# Input: $int = 10020003
+# Output: 000
+
+use Modern::Perl;
+
+@ARGV==1 or die "Usage: $0 INT\n";
+(my $int = shift) =~ /^\d+$/ or die "Usage: $0 INT\n";
+
+if ($int =~ /((\d)\2\2+)/ && length($1) == 3) {
+ say $1;
+}
+else {
+ say -1;
+}
diff --git a/challenge-282/paulo-custodio/perl/ch-2.pl b/challenge-282/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..7aa10cd168
--- /dev/null
+++ b/challenge-282/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+# Challenge 282
+#
+# Task 2: Changing Keys
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an alphabetic string, $str, as typed by user.
+#
+# Write a script to find the number of times user had to change the key to type
+# the given string. Changing key is defined as using a key different from the
+# last used key. The shift and caps lock keys won’t be counted.
+#
+# Example 1
+#
+# Input: $str = 'pPeERrLl'
+# Ouput: 3
+#
+# p -> P : 0 key change
+# P -> e : 1 key change
+# e -> E : 0 key change
+# E -> R : 1 key change
+# R -> r : 0 key change
+# r -> L : 1 key change
+# L -> l : 0 key change
+#
+# Example 2
+#
+# Input: $str = 'rRr'
+# Ouput: 0
+#
+# Example 3
+#
+# Input: $str = 'GoO'
+# Ouput: 1
+
+use Modern::Perl;
+
+@ARGV==1 or die "Usage: $0 STR\n";
+
+my $str = uc(shift);
+$str =~ s/(.)\1*/$1/g;
+say length($str)-1;
diff --git a/challenge-282/paulo-custodio/t/test-1.yaml b/challenge-282/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..3b9ddc2d61
--- /dev/null
+++ b/challenge-282/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 12344456
+ input:
+ output: 444
+- setup:
+ cleanup:
+ args: 1233334
+ input:
+ output: -1
+- setup:
+ cleanup:
+ args: 10020003
+ input:
+ output: 000
diff --git a/challenge-282/paulo-custodio/t/test-2.yaml b/challenge-282/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..db7534adbc
--- /dev/null
+++ b/challenge-282/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: pPeERrLl
+ input:
+ output: 3
+- setup:
+ cleanup:
+ args: rRr
+ input:
+ output: 0
+- setup:
+ cleanup:
+ args: GoO
+ input:
+ output: 1