aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-08-13 17:52:51 +0200
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-08-16 13:57:02 +0200
commit6174ca38c229fabf1a96f81d9534a102d349ad6a (patch)
treeb1d2f93176c90212deeb01cabf71f0660733e429
parent364bdb85c8b187020dd0c800098dcc1449856a80 (diff)
downloadperlweeklychallenge-club-6174ca38c229fabf1a96f81d9534a102d349ad6a.tar.gz
perlweeklychallenge-club-6174ca38c229fabf1a96f81d9534a102d349ad6a.tar.bz2
perlweeklychallenge-club-6174ca38c229fabf1a96f81d9534a102d349ad6a.zip
Solution to task 2
-rwxr-xr-xchallenge-282/jo-37/perl/ch-2.pl65
1 files changed, 65 insertions, 0 deletions
diff --git a/challenge-282/jo-37/perl/ch-2.pl b/challenge-282/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..470d3be2b4
--- /dev/null
+++ b/challenge-282/jo-37/perl/ch-2.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -s
+
+use v5.24;
+use Test2::V0;
+use utf8;
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [STR]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+STR
+ a string
+
+EOS
+
+
+### Input and Output
+
+say changing_keys(shift);
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/08/16/ch-282.html#task-2
+
+
+sub changing_keys {
+ (() = lc(shift) =~ /(.)\1*/g) - 1;
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is changing_keys('pPeERrLl'), 3, 'example 1';
+ is changing_keys('rRr'), 0, 'example 2';
+ is changing_keys('GoO'), 1, 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+
+ is changing_keys('ßss'), 1, 'multiple lower';
+ is changing_keys('ßSS'), 1, 'multiple upper';
+ is changing_keys('Σς'), 1, 'different keys';
+ is changing_keys('σς'), 1, 'different keys';
+ is changing_keys('Σσ'), 0, 'same key';
+ }
+
+ done_testing;
+ exit;
+}