From e14476b64148f02531bbd641d012cf835aa3826a Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Thu, 5 May 2022 18:42:48 +0430 Subject: Added solutions to challenge 163 --- challenge-163/deadmarshal/lua/ch-2.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-163/deadmarshal/lua/ch-2.lua (limited to 'challenge-163/deadmarshal/lua/ch-2.lua') 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)) + -- cgit