diff options
| author | E. Choroba <choroba@matfyz.cz> | 2024-08-13 12:32:32 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2024-08-13 12:32:32 +0200 |
| commit | e440847bb97e3c1e755dc03f94674df29e7ac148 (patch) | |
| tree | 1734ff5a876561fba2ff25ad099f3f3a8bf4d007 | |
| parent | 4789e5484d19dd33b93402051a862ac21427b762 (diff) | |
| download | perlweeklychallenge-club-e440847bb97e3c1e755dc03f94674df29e7ac148.tar.gz perlweeklychallenge-club-e440847bb97e3c1e755dc03f94674df29e7ac148.tar.bz2 perlweeklychallenge-club-e440847bb97e3c1e755dc03f94674df29e7ac148.zip | |
Add solutions to 282: Good Integer & Changing Keys by E. Choroba
| -rwxr-xr-x | challenge-282/e-choroba/perl/ch-1.pl | 28 | ||||
| -rwxr-xr-x | challenge-282/e-choroba/perl/ch-2.pl | 14 |
2 files changed, 42 insertions, 0 deletions
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'; |
