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/lua/ch-1.lua | |
| 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/lua/ch-1.lua')
| -rwxr-xr-x | challenge-211/roger-bell-west/lua/ch-1.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/challenge-211/roger-bell-west/lua/ch-1.lua b/challenge-211/roger-bell-west/lua/ch-1.lua new file mode 100755 index 0000000000..50dfb58b1c --- /dev/null +++ b/challenge-211/roger-bell-west/lua/ch-1.lua @@ -0,0 +1,46 @@ +#! /usr/bin/lua + +function toeplitzmatrix(a) + local ym = #a - 1 + local xm = #(a[1]) - 1 + local toeplitz = true + for xb = (1 - xm), (ym - 1) do + local init = true + local tv = 0 + for xi = xb, xb + xm do + if xi >= 0 and xi <= xm then + local x = xi + 1 + local yi = xi - xb + if yi >= 0 and yi <= ym then + local y = yi + 1 + if init then + init = false + tv = a[y][x] + elseif a[y][x] ~= tv then + toeplitz = false + break + end + end + end + end + if not toeplitz then + break + end + end + return toeplitz +end + +if toeplitzmatrix({{4, 3, 2, 1}, {5, 4, 3, 2}, {6, 5, 4, 3}}) then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if not toeplitzmatrix({{1, 2, 3}, {3, 2, 1}}) then + io.write("Pass") +else + io.write("FAIL") +end +print("") + |
