aboutsummaryrefslogtreecommitdiff
path: root/challenge-271/deadmarshal/lua/ch-1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-271/deadmarshal/lua/ch-1.lua')
-rw-r--r--challenge-271/deadmarshal/lua/ch-1.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-271/deadmarshal/lua/ch-1.lua b/challenge-271/deadmarshal/lua/ch-1.lua
new file mode 100644
index 0000000000..159d148473
--- /dev/null
+++ b/challenge-271/deadmarshal/lua/ch-1.lua
@@ -0,0 +1,23 @@
+#!/usr/bin/env lua
+
+local function sum(t)
+ assert(type(t) == 'table','t must be a table!')
+ local s = 0
+ for i=1,#t do s = s + t[i] end
+ return s
+end
+
+local function maximum_ones(t)
+ assert(type(t) == 'table','t must be a table!')
+ local max = 0
+ for i=1,#t do
+ local s = sum(t[i])
+ if s > max then max = s end
+ end
+ return max
+end
+
+print(maximum_ones{{0,1},{1,0}})
+print(maximum_ones{{0,0,0},{1,0,1}})
+print(maximum_ones{{0,0},{1,1},{0,0}})
+