aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-282/jo-37/blog.txt1
-rwxr-xr-xchallenge-282/jo-37/perl/ch-1.pl64
-rwxr-xr-xchallenge-282/jo-37/perl/ch-2.pl65
3 files changed, 130 insertions, 0 deletions
diff --git a/challenge-282/jo-37/blog.txt b/challenge-282/jo-37/blog.txt
new file mode 100644
index 0000000000..9c50658202
--- /dev/null
+++ b/challenge-282/jo-37/blog.txt
@@ -0,0 +1 @@
+https://github.sommrey.de/the-bears-den/2024/08/16/ch-282.html
diff --git a/challenge-282/jo-37/perl/ch-1.pl b/challenge-282/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..b84c47cab9
--- /dev/null
+++ b/challenge-282/jo-37/perl/ch-1.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl -s
+
+use v5.24;
+use Test2::V0;
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [N]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+N
+ a number (or string)
+
+EOS
+
+
+### Input and Output
+
+say good_integer(shift) // -1;
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/08/16/ch-282.html#task-1
+
+
+sub good_integer {
+ (shift =~ /((.)(?<!(?=\2)..)\2{2})(?!\2)/)[0];
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is good_integer(12344456), 444, 'example 1';
+ is good_integer(1233334), U(), 'example 2';
+ is good_integer(10020003), '000', 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+
+ is good_integer(1112), 111, 'at start';
+ is good_integer(1222), 222, 'at end';
+ is good_integer(111), 111, 'completely good';
+ is good_integer('abbbaa'), 'bbb', 'not a number';
+ is good_integer(122234445), 222, 'pick the first match';
+ }
+
+ done_testing;
+ exit;
+}
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;
+}