From e440847bb97e3c1e755dc03f94674df29e7ac148 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Tue, 13 Aug 2024 12:32:32 +0200 Subject: Add solutions to 282: Good Integer & Changing Keys by E. Choroba --- challenge-282/e-choroba/perl/ch-1.pl | 28 ++++++++++++++++++++++++++++ challenge-282/e-choroba/perl/ch-2.pl | 14 ++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 challenge-282/e-choroba/perl/ch-1.pl create mode 100755 challenge-282/e-choroba/perl/ch-2.pl diff --git a/challenge-282/e-choroba/perl/ch-1.pl b/challenge-282/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..6387955dce --- /dev/null +++ b/challenge-282/e-choroba/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub good_integer($int) { + if ($int =~ /(?:^ # Start at the beginning + | (.) (?! \1 ) ) # or after a digit not followed by itself. + ( (.) \3{2} # Find a digit repeated 3 times + (?! \3 ) # but not more. + ) /x + ) { + return $2 + } else { + return -1 + } +} + +use Test2::V0; +plan tests => 3 + 3; + +is good_integer(12344456), '444', 'Example 1'; +is good_integer(1233334), '-1', 'Example 2'; +is good_integer(10020003), '000', 'Example 3'; + +is good_integer(111222), in_set('111', '222'), 'More than one group'; +is good_integer(1112), '111', 'Beginning'; +is good_integer(1222), '222', 'End'; diff --git a/challenge-282/e-choroba/perl/ch-2.pl b/challenge-282/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..6edfa0754f --- /dev/null +++ b/challenge-282/e-choroba/perl/ch-2.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub changing_keys($str) { + return length($str =~ tr/A-Za-z/a-za-z/sr) - 1 +} + +use Test::More tests => 3; + +is changing_keys('pPeERrLl'), 3, 'Example 1'; +is changing_keys('rRr'), 0, 'Example 2'; +is changing_keys('GoO'), 1, 'Example 3'; -- cgit