aboutsummaryrefslogtreecommitdiff
path: root/challenge-278
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2024-07-22 10:29:49 +0000
committerNiels van Dijke <perlboy@cpan.org>2024-07-22 10:29:49 +0000
commit8a267312f3c5c02f70e31ca1a5dc3afabd9a82d1 (patch)
tree902b1c9cbc22b3aaa46fbdebd2f1c1881f93c894 /challenge-278
parenta01b4632d06c441f117d9c6a1c4794384f665c0f (diff)
downloadperlweeklychallenge-club-8a267312f3c5c02f70e31ca1a5dc3afabd9a82d1.tar.gz
perlweeklychallenge-club-8a267312f3c5c02f70e31ca1a5dc3afabd9a82d1.tar.bz2
perlweeklychallenge-club-8a267312f3c5c02f70e31ca1a5dc3afabd9a82d1.zip
w278 & w279, task 1 & 2
Diffstat (limited to 'challenge-278')
-rwxr-xr-xchallenge-278/perlboy1967/perl/ch1.pl38
-rwxr-xr-xchallenge-278/perlboy1967/perl/ch2.pl35
2 files changed, 73 insertions, 0 deletions
diff --git a/challenge-278/perlboy1967/perl/ch1.pl b/challenge-278/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..fe27751f6b
--- /dev/null
+++ b/challenge-278/perlboy1967/perl/ch1.pl
@@ -0,0 +1,38 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 278
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-278
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Sort String
+Submitted by: Mohammad Sajid Anwar
+
+You are given a shuffle string, $str.
+
+Write a script to return the sorted string.
+
+|| A string is shuffled by appending word position to each word.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0 qw(-no_srand);
+
+sub sortString ($str) {
+ join ' ',map {$_->[0]} sort {$$a[1]<=>$$b[1]} map {[/(\D+)(\d+)/]} split /\s+/,$str
+}
+
+is(sortString('and2 Raku3 cousins5 Perl1 are4'),
+ 'Perl and Raku are cousins');
+is(sortString('guest6 Python1 most4 the3 popular5 is2 language7'),
+ 'Python is the most popular guest language');
+is(sortString('Challenge3 The1 Weekly2'),
+ 'The Weekly Challenge');
+
+done_testing;
diff --git a/challenge-278/perlboy1967/perl/ch2.pl b/challenge-278/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..93f2536312
--- /dev/null
+++ b/challenge-278/perlboy1967/perl/ch2.pl
@@ -0,0 +1,35 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 278
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-278
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Reverse Word
+Submitted by: Mohammad Sajid Anwar
+
+You are given a word, $word and a character, $char.
+
+Write a script to replace the substring up to and including $char with
+its characters sorted alphabetically. If the $char doesn’t exist then
+DON'T do anything.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0 qw(-no_srand);
+
+sub reverseWord ($word,$char) {
+ $word =~ s#^(.*?$char)#join('',sort split //,$1)#er;
+}
+
+is(reverseWord('challenge','e'),'acehllnge');
+is(reverseWord('programming','a'),'agoprrmming');
+is(reverseWord('champion','b'),'champion');
+
+done_testing;