aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-04-07 01:35:23 +0100
committerGitHub <noreply@github.com>2023-04-07 01:35:23 +0100
commit1f25293425e50ac9d91c69464d3b374a35d62825 (patch)
treeae18da872a03e3f9786461b4c83b0955324acfad
parent4832e5912bf07b2bad3aff3156c4ccc1bc01d830 (diff)
parent561e87631dff36bc768ac869df26ca044d75be8a (diff)
downloadperlweeklychallenge-club-1f25293425e50ac9d91c69464d3b374a35d62825.tar.gz
perlweeklychallenge-club-1f25293425e50ac9d91c69464d3b374a35d62825.tar.bz2
perlweeklychallenge-club-1f25293425e50ac9d91c69464d3b374a35d62825.zip
Merge pull request #7853 from manfredi/challenge-211
Solution for Task #1
-rwxr-xr-xchallenge-211/manfredi/perl/ch-1.pl41
-rwxr-xr-xchallenge-211/manfredi/python/ch-1.py33
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-211/manfredi/perl/ch-1.pl b/challenge-211/manfredi/perl/ch-1.pl
new file mode 100755
index 0000000000..02ebabe406
--- /dev/null
+++ b/challenge-211/manfredi/perl/ch-1.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/env perl
+
+use v5.36;
+use Data::Dumper;
+
+say "challenge-211-task1";
+
+# Task 1: Toeplitz Matrix
+# You are given a matrix m x n
+# Write a script to find out if the given matrix is Toeplitz Matrix
+
+my $matrix = [
+ [4, 3, 2, 1],
+ [5, 4, 3, 2],
+ [6, 5, 4, 3],
+];
+
+# my $matrix = [
+# [1, 2, 3],
+# [3, 2, 1],
+# ];
+
+say Dumper($matrix);
+
+my $rows = @$matrix;
+my $cols = @{$matrix->[0]};
+my $is_toeplitz = 1;
+
+ROW:
+for my $row (0..$rows-2) {
+ for my $col (0..$cols-2) {
+ say $$matrix[$row][$col], " ", $$matrix[$row+1][$col+1];
+ unless ($$matrix[$row][$col] == $$matrix[$row+1][$col+1]) {
+ $is_toeplitz = 0;
+ last ROW;
+ }
+ }
+}
+
+say $is_toeplitz ? "Toeplitz Matrix!" : "Not Toeplitz Matrix";
+
diff --git a/challenge-211/manfredi/python/ch-1.py b/challenge-211/manfredi/python/ch-1.py
new file mode 100755
index 0000000000..fed72bd18f
--- /dev/null
+++ b/challenge-211/manfredi/python/ch-1.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+# Python 3.9.2 on Debian GNU/Linux 11 (bullseye)
+
+print('challenge-211-task1')
+
+# Task 1: Toeplitz Matrix
+# You are given a matrix m x n
+# Write a script to find out if the given matrix is Toeplitz Matrix
+
+matrix = [
+ [4, 3, 2, 1],
+ [5, 4, 3, 2],
+ [6, 5, 4, 3],
+]
+
+# matrix = [
+# [1, 2, 3],
+# [3, 2, 1],
+# ]
+
+print(matrix)
+is_toeplitz = True
+
+for row in range(0, len(matrix) - 1):
+ if not is_toeplitz: break
+ for col in range(0, len(matrix[row]) - 1):
+ if not is_toeplitz: break
+ print(matrix[row][col], matrix[row+1][col+1])
+ if not matrix[row][col] == matrix[row+1][col+1]:
+ is_toeplitz = False
+
+
+print('Toeplitz Matrix!') if is_toeplitz else print('Not Toeplitz Matrix')