aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-26 17:17:41 +0100
committerGitHub <noreply@github.com>2024-07-26 17:17:41 +0100
commit6a72b7b09c15bef8b4482c0b22bd3ee89d727cdc (patch)
tree70fef21153d6911c2b6d450bbd49c46538fd5f93
parent9a4dd9000bb589778b7f7b0036e1876ad6090c06 (diff)
parent0ae864bc7d061ed7d04d9d4b90a2a282e84d538e (diff)
downloadperlweeklychallenge-club-6a72b7b09c15bef8b4482c0b22bd3ee89d727cdc.tar.gz
perlweeklychallenge-club-6a72b7b09c15bef8b4482c0b22bd3ee89d727cdc.tar.bz2
perlweeklychallenge-club-6a72b7b09c15bef8b4482c0b22bd3ee89d727cdc.zip
Merge pull request #10495 from jo-37/contrib
Solutions to challenge 279
-rw-r--r--challenge-279/jo-37/blog.txt1
-rwxr-xr-xchallenge-279/jo-37/perl/ch-1.pl68
-rwxr-xr-xchallenge-279/jo-37/perl/ch-2.pl60
3 files changed, 129 insertions, 0 deletions
diff --git a/challenge-279/jo-37/blog.txt b/challenge-279/jo-37/blog.txt
new file mode 100644
index 0000000000..f230a186cf
--- /dev/null
+++ b/challenge-279/jo-37/blog.txt
@@ -0,0 +1 @@
+https://github.sommrey.de/the-bears-den/2024/07/26/ch-279.html
diff --git a/challenge-279/jo-37/perl/ch-1.pl b/challenge-279/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..dc492b5b5a
--- /dev/null
+++ b/challenge-279/jo-37/perl/ch-1.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl -s
+
+use v5.24;
+use Test2::V0;
+use experimental 'signatures';
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV == 2;
+usage: $0 [-examples] [-tests] [LETTERS WEIGHTS]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+LETTERS
+ list of letters, optionally separated by commas
+
+WEIGHTS
+ list of weights, optionally separated by commas
+
+EOS
+
+
+### Input and Output
+
+say sort_letters(map [split /,*/, $_], @ARGV);
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/07/26/ch-279.html#task-1
+
+
+sub sort_letters ($letters, $weights) {
+ (\my @word)->@[map $_ - 1, @$weights] = @$letters;
+ join '', @word;
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is sort_letters(['R', 'E', 'P', 'L'], [3, 2, 1, 4]),
+ 'PERL', 'example 1';
+
+ is sort_letters(['A', 'U', 'R', 'K'], [2, 4, 1, 3]),
+ 'RAKU', 'example 2';
+
+ is sort_letters(['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]),
+ 'PYTHON', 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+ }
+
+ done_testing;
+ exit;
+}
diff --git a/challenge-279/jo-37/perl/ch-2.pl b/challenge-279/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..6be9ea5a98
--- /dev/null
+++ b/challenge-279/jo-37/perl/ch-2.pl
@@ -0,0 +1,60 @@
+#!/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] [STR]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+STR
+ a string
+
+EOS
+
+
+### Input and Output
+
+say +(qw(false true))[split_string(shift)];
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/07/26/ch-279.html#task-2
+
+
+sub split_string {
+ local $_ = shift;
+
+ !(tr/aeiouAEIOU// % 2);
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ ok !split_string("perl"), 'example 1';
+ ok split_string("book"), 'example 2';
+ ok split_string("good morning"), 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+ }
+
+ done_testing;
+ exit;
+}