aboutsummaryrefslogtreecommitdiff
path: root/challenge-163/deadmarshal/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-163/deadmarshal/lua/ch-2.lua')
-rw-r--r--challenge-163/deadmarshal/lua/ch-2.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/challenge-163/deadmarshal/lua/ch-2.lua b/challenge-163/deadmarshal/lua/ch-2.lua
new file mode 100644
index 0000000000..c4f666d16f
--- /dev/null
+++ b/challenge-163/deadmarshal/lua/ch-2.lua
@@ -0,0 +1,15 @@
+function summations(t)
+ assert(type(t) == 'table', 't must be a table!')
+ for i=1, #t do
+ for j=i+1, #t-1 do
+ t[j+1] = t[j] + t[j+1]
+ end
+ end
+ return t[#t]
+end
+
+local t = {1,2,3,4,5}
+local t2 = {1,3,5,7,9}
+print(summations(t))
+print(summations(t2))
+