diff options
Diffstat (limited to 'challenge-251/roger-bell-west/lua/ch-2.lua')
| -rwxr-xr-x | challenge-251/roger-bell-west/lua/ch-2.lua | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-251/roger-bell-west/lua/ch-2.lua b/challenge-251/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..b6f31930c0 --- /dev/null +++ b/challenge-251/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,54 @@ +#! /usr/bin/lua + +function luckynumbers(a) + local maxs = {} + for x = 1, #(a[1]) do + local max = {0, 0, 0} + for y = 1, #a do + if a[y][x] > max[1] then + max = {a[y][x], y, x} + end + end + table.insert(maxs, max) + end + local mins = {} + for y = 1, #a do + local min = {a[y][1], y, 1} + for x = 1, #(a[1]) do + if a[y][x] < min[1] then + min = {a[y][x], y, x} + end + end + table.insert(mins, min) + end + for i, v in ipairs(mins) do + for j, w in ipairs(maxs) do + if v[1] == w[1] and v[2] == w[2] and v[3] == w[3] then + return v[1] + end + end + end + return -1 +end + +if luckynumbers({{3, 7, 9}, {9, 11, 13}, {15, 16, 17}}) == 15 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if luckynumbers({{1, 10, 4, 2}, {9, 3, 8, 7}, {15, 16, 17, 12}}) == 12 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if luckynumbers({{7, 8}, {1, 2}}) == 7 then + io.write("Pass") +else + io.write("FAIL") +end +print("") + |
