aboutsummaryrefslogtreecommitdiff
path: root/challenge-253
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-01-22 18:45:40 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-01-22 18:45:40 +0000
commit8db85cd488ebedbbda40cca5403676ce0ed8e072 (patch)
treed33d82158a36712744dfe056a614af5efd7d392d /challenge-253
parente5950fec13757372c56fd4a6fe34acb64e03f261 (diff)
downloadperlweeklychallenge-club-8db85cd488ebedbbda40cca5403676ce0ed8e072.tar.gz
perlweeklychallenge-club-8db85cd488ebedbbda40cca5403676ce0ed8e072.tar.bz2
perlweeklychallenge-club-8db85cd488ebedbbda40cca5403676ce0ed8e072.zip
- Added solutions by Eric Cheung.
- Added solutions by Laurent Rosenfeld. - Added solutions by Mark Anderson. - Added solutions by Niels van Dijke. - Added solutions by PokGoPun. - Added solutions by Luca Ferrari. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan.
Diffstat (limited to 'challenge-253')
-rwxr-xr-xchallenge-253/eric-cheung/python/ch-1.py14
-rwxr-xr-xchallenge-253/eric-cheung/python/ch-2.py17
-rw-r--r--challenge-253/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-253/laurent-rosenfeld/perl/ch-1.pl18
-rw-r--r--challenge-253/laurent-rosenfeld/raku/ch-1.raku18
-rwxr-xr-xchallenge-253/perlboy1967/perl/ch-1.pl (renamed from challenge-253/perlboy1967/perl/ch1.pl)0
-rwxr-xr-xchallenge-253/perlboy1967/perl/ch-2.pl (renamed from challenge-253/perlboy1967/perl/ch2.pl)0
7 files changed, 68 insertions, 0 deletions
diff --git a/challenge-253/eric-cheung/python/ch-1.py b/challenge-253/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..ac1c18f9c5
--- /dev/null
+++ b/challenge-253/eric-cheung/python/ch-1.py
@@ -0,0 +1,14 @@
+
+## Example 1
+arrWords = ["one.two.three", "four.five", "six"]
+strSeparator = "."
+
+## Example 2
+## arrWords = ["$perl$$", "$$raku$"]
+## strSeparator = "$"
+
+arrOutput = []
+for strLoop in arrWords:
+ arrOutput = arrOutput + strLoop.split(strSeparator)
+
+print (",".join(["\"" + strLoop + "\"" for strLoop in arrOutput if strLoop]))
diff --git a/challenge-253/eric-cheung/python/ch-2.py b/challenge-253/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..91e11aaa8b
--- /dev/null
+++ b/challenge-253/eric-cheung/python/ch-2.py
@@ -0,0 +1,17 @@
+
+def IsWeaker (rowA, rowB):
+ return True if rowA.count(1) <= rowB.count(1) else False
+
+## arrMatrix = [[1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]] ## Example 1
+arrMatrix = [[1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0]] ## Example 2
+
+arrIndx = [nIndx for nIndx in range(len(arrMatrix))]
+
+for nRowLoop in range(len(arrIndx) - 1):
+ for nColLoop in range(nRowLoop + 1, len(arrIndx)):
+ if not IsWeaker (arrMatrix[arrIndx[nRowLoop]], arrMatrix[arrIndx[nColLoop]]):
+ vTemp = arrIndx[nRowLoop]
+ arrIndx[nRowLoop] = arrIndx[nColLoop]
+ arrIndx[nColLoop] = vTemp
+
+print (arrIndx)
diff --git a/challenge-253/laurent-rosenfeld/blog.txt b/challenge-253/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..3ce6bf5981
--- /dev/null
+++ b/challenge-253/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/laurent_r/2024/01/perl-weekly-challenge-253-split-strings.html
diff --git a/challenge-253/laurent-rosenfeld/perl/ch-1.pl b/challenge-253/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..8cccb2a672
--- /dev/null
+++ b/challenge-253/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use feature 'say';
+
+sub split_strings {
+ my ($sep, @strings) = @_;
+ $sep = quotemeta $sep;
+ my @result = grep { /\w+/ }
+ map { split $sep, $_ } @strings;
+ return @result;
+}
+
+my @tests = ( [ '.', ["one.two.three","four.five","six"] ],
+ [ '$', ['$perl$$', '$$raku$'] ] );
+for my $test (@tests) {
+ printf "%-30s => ", "@{$test->[1]}";
+ say join " ", split_strings $test->[0], @{$test->[1]};
+}
diff --git a/challenge-253/laurent-rosenfeld/raku/ch-1.raku b/challenge-253/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..48e90b38e6
--- /dev/null
+++ b/challenge-253/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,18 @@
+sub split-strings (:$sep, :@strings) {
+ my @result = grep { /\w+/ }, flat
+ map { split $sep, $_ }, @strings;
+ return @result;
+}
+
+
+my @tests = {
+ 'separator' => '.',
+ 'string' => ("one.two.three","four.five","six")
+ }, {
+ 'separator' => '$',
+ 'string' => ('$perl$$', '$$raku$')};
+for @tests -> %test {
+ printf "%-30s => ", %test<string>;
+ say split-strings(sep => %test<separator>,
+ strings => %test<string>);
+}
diff --git a/challenge-253/perlboy1967/perl/ch1.pl b/challenge-253/perlboy1967/perl/ch-1.pl
index b93afab37f..b93afab37f 100755
--- a/challenge-253/perlboy1967/perl/ch1.pl
+++ b/challenge-253/perlboy1967/perl/ch-1.pl
diff --git a/challenge-253/perlboy1967/perl/ch2.pl b/challenge-253/perlboy1967/perl/ch-2.pl
index 58d1e27c8a..58d1e27c8a 100755
--- a/challenge-253/perlboy1967/perl/ch2.pl
+++ b/challenge-253/perlboy1967/perl/ch-2.pl