diff options
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("") + |
