aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-24 19:07:12 +0100
committerGitHub <noreply@github.com>2024-04-24 19:07:12 +0100
commite3f6f2c63e9d4d72d6c99f1e5c28771abd7470d5 (patch)
tree9288089bc320554743a9e5995e0abff1ec90245e
parent20eda9801d7005334dead24331e1c1ce4bf9e13a (diff)
parentd54f094375b7c3763e45d194514555e9870efe2c (diff)
downloadperlweeklychallenge-club-e3f6f2c63e9d4d72d6c99f1e5c28771abd7470d5.tar.gz
perlweeklychallenge-club-e3f6f2c63e9d4d72d6c99f1e5c28771abd7470d5.tar.bz2
perlweeklychallenge-club-e3f6f2c63e9d4d72d6c99f1e5c28771abd7470d5.zip
Merge pull request #9986 from deadmarshal/TWC266
TWC266
-rw-r--r--challenge-266/deadmarshal/blog.txt1
-rw-r--r--challenge-266/deadmarshal/perl/ch-1.pl15
-rw-r--r--challenge-266/deadmarshal/perl/ch-2.pl31
-rw-r--r--challenge-266/deadmarshal/raku/ch-1.raku13
-rw-r--r--challenge-266/deadmarshal/raku/ch-2.raku26
5 files changed, 86 insertions, 0 deletions
diff --git a/challenge-266/deadmarshal/blog.txt b/challenge-266/deadmarshal/blog.txt
new file mode 100644
index 0000000000..77c8b026ea
--- /dev/null
+++ b/challenge-266/deadmarshal/blog.txt
@@ -0,0 +1 @@
+https://deadmarshal.blogspot.com/2024/04/twc266.html
diff --git a/challenge-266/deadmarshal/perl/ch-1.pl b/challenge-266/deadmarshal/perl/ch-1.pl
new file mode 100644
index 0000000000..f26f52e9cf
--- /dev/null
+++ b/challenge-266/deadmarshal/perl/ch-1.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Data::Show;
+
+sub uncommon_words{
+ my %h;
+ $h{lc $_}++ foreach split /\W+/, $_[0] . ' ' . $_[1];
+ sort grep{$h{$_} == 1} keys %h;
+}
+
+print show uncommon_words('Mango is sweet','Mango is sour');
+print show uncommon_words('Mango Mango','Orange');
+print show uncommon_words('Mango is Mango','Orange is Orange');
+
diff --git a/challenge-266/deadmarshal/perl/ch-2.pl b/challenge-266/deadmarshal/perl/ch-2.pl
new file mode 100644
index 0000000000..9559937166
--- /dev/null
+++ b/challenge-266/deadmarshal/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+sub x_matrix{
+ my ($mat) = @_;
+ my $n = @$mat;
+ foreach my $i(0..$n-1){
+ foreach my $j(0..$n-1){
+ if($i == $j || $i+$j == $n-1){
+ return 0 if $mat->[$i][$j] == 0
+ }
+ elsif($mat->[$i][$j] != 0){return 0}
+ }
+ }
+ 1
+}
+
+printf "%d\n",x_matrix([[1,0,0,2],
+ [0,3,4,0],
+ [0,5,6,0],
+ [7,0,0,1]]);
+
+printf "%d\n",x_matrix([[1,2,3],
+ [4,5,6],
+ [7,8,9]]);
+
+printf "%d\n",x_matrix([[1,0,2],
+ [0,3,0],
+ [4,0,5]]);
+
diff --git a/challenge-266/deadmarshal/raku/ch-1.raku b/challenge-266/deadmarshal/raku/ch-1.raku
new file mode 100644
index 0000000000..c0160267a7
--- /dev/null
+++ b/challenge-266/deadmarshal/raku/ch-1.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+
+sub uncommon-words($s1,$s2)
+{
+ my %h;
+ %h{lc $_}++ for split /\W+/, $s1 ~ ' ' ~ $s2;
+ (%h.keys.grep: {%h{$_} == 1}).sort
+}
+
+say uncommon-words('Mango is sweet','Mango is sour');
+say uncommon-words('Mango Mango','Orange');
+say uncommon-words('Mango is Mango','Orange is Orange');
+
diff --git a/challenge-266/deadmarshal/raku/ch-2.raku b/challenge-266/deadmarshal/raku/ch-2.raku
new file mode 100644
index 0000000000..eee7b8bfe2
--- /dev/null
+++ b/challenge-266/deadmarshal/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+sub x-matrix(@mat){
+ for 0..@mat.end -> $i {
+ for 0..@mat.end -> $j {
+ if ($i == $j || $i+$j == @mat.end) {
+ return False if @mat[$i][$j] == 0
+ }
+ elsif (@mat[$i][$j] != 0) {return False}
+ }
+ }
+ True
+}
+
+say x-matrix([[1,0,0,2],
+ [0,3,4,0],
+ [0,5,6,0],
+ [7,0,0,1]]);
+
+say x-matrix([[1,2,3],
+ [4,5,6],
+ [7,8,9]]);
+
+say x-matrix([[1,0,2],
+ [0,3,0],
+ [4,0,5]]);