aboutsummaryrefslogtreecommitdiff
path: root/challenge-211
diff options
context:
space:
mode:
authorMariano Spadaccini <spadacciniweb@gmail.com>2023-04-06 14:39:52 +0200
committerMariano Spadaccini <spadacciniweb@gmail.com>2023-04-06 14:39:52 +0200
commitd4bacf05e9f6837997f06554a1c6a971d42ae6ad (patch)
tree755bd2eb19e9eda6d69b90f366d4baed1e6186c5 /challenge-211
parent3457c7a15b48e32fa9eb55630657287942ca0d98 (diff)
downloadperlweeklychallenge-club-d4bacf05e9f6837997f06554a1c6a971d42ae6ad.tar.gz
perlweeklychallenge-club-d4bacf05e9f6837997f06554a1c6a971d42ae6ad.tar.bz2
perlweeklychallenge-club-d4bacf05e9f6837997f06554a1c6a971d42ae6ad.zip
Add ch-1.go
Diffstat (limited to 'challenge-211')
-rw-r--r--challenge-211/spadacciniweb/go/ch-1.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/challenge-211/spadacciniweb/go/ch-1.go b/challenge-211/spadacciniweb/go/ch-1.go
new file mode 100644
index 0000000000..97d6d47354
--- /dev/null
+++ b/challenge-211/spadacciniweb/go/ch-1.go
@@ -0,0 +1,59 @@
+/*
+Task 1: Toeplitz Matrix
+Submitted by: Mohammad S Anwar
+
+You are given a matrix m x n.
+Write a script to find out if the given matrix is Toeplitz Matrix.
+A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
+
+
+Example 1
+Input: @matrix = [ [4, 3, 2, 1],
+ [5, 4, 3, 2],
+ [6, 5, 4, 3],
+ ]
+Output: true
+
+Example 2
+Input: @matrix = [ [1, 2, 3],
+ [3, 2, 1],
+ ]
+Output: false
+*/
+
+package main
+
+import (
+ "fmt"
+)
+
+func check_toeplitz(m [][]int) bool {
+ rows := len(m)
+ cols := len(m[0])
+ var dimens int = rows
+ if (cols < rows) {
+ dimens = cols
+ }
+ val := m[0][0]
+ for i := 0; i < dimens; i++ {
+ if m[i][i] != val {
+ return false
+ }
+ }
+ return true
+}
+
+func main() {
+ matrix1 := [][]int{
+ {4, 3, 2, 1},
+ {5, 4, 3, 2},
+ {6, 5, 4, 3},
+ }
+ fmt.Println(check_toeplitz(matrix1))
+
+ matrix2 := [][]int{
+ {1, 2, 3},
+ {3, 2, 1},
+ }
+ fmt.Println(check_toeplitz(matrix2))
+}