diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2023-04-07 11:52:10 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2023-04-07 11:52:10 +0100 |
| commit | c27917c2860cb2a203262d9cdeebd264c29456f2 (patch) | |
| tree | 3b024d7c86e48d197d470779ceca31d31a6971a5 /challenge-211/roger-bell-west/python/ch-1.py | |
| parent | bd0ea1891b53fb4cff93b57af6481f37dd268509 (diff) | |
| parent | 419cb48e0bd7736f9b625a9f60ce52bc77be8f7a (diff) | |
| download | perlweeklychallenge-club-c27917c2860cb2a203262d9cdeebd264c29456f2.tar.gz perlweeklychallenge-club-c27917c2860cb2a203262d9cdeebd264c29456f2.tar.bz2 perlweeklychallenge-club-c27917c2860cb2a203262d9cdeebd264c29456f2.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-211/roger-bell-west/python/ch-1.py')
| -rwxr-xr-x | challenge-211/roger-bell-west/python/ch-1.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-211/roger-bell-west/python/ch-1.py b/challenge-211/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..a1c6e0e380 --- /dev/null +++ b/challenge-211/roger-bell-west/python/ch-1.py @@ -0,0 +1,34 @@ +#! /usr/bin/python3 + +import unittest + +def toeplitzmatrix(a): + ym = len(a) - 1 + xm = len(a[0]) - 1 + toeplitz = True + for xb in range(1 - xm, ym): + init = True + tv = 0 + for x in range(xb, xb + xm + 1): + if x >= 0 and x <= xm: + y = x - xb + if y >= 0 and y <= ym: + if init: + init = False + tv = a[y][x] + elif a[y][x] != tv: + toeplitz = False + break + if not toeplitz: + break + return toeplitz + +class TestToeplitzmatrix(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(toeplitzmatrix([[4, 3, 2, 1], [5, 4, 3, 2], [6, 5, 4, 3]]), True, 'example 1') + + def test_ex2(self): + self.assertEqual(toeplitzmatrix([[1, 2, 3], [3, 2, 1]]), False, 'example 2') + +unittest.main() |
