The problem is from SPOJ Online Judge [problem description]
This problem is for beginner, and we use this to continue practise our LUA skills.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | -- split a string into array function split(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match); end return result; end s = split(io.read(), [[ ]]) a = tonumber(s[1]) b = tonumber(s[2]) s = 0 for i = a, b do s = s + i * i end print(s) |
-- split a string into array function split(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match); end return result; end s = split(io.read(), [[ ]]) a = tonumber(s[1]) b = tonumber(s[2]) s = 0 for i = a, b do s = s + i * i end print(s)
The solution is to implement a loop to sum the squares of each number given a range.
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
195 wordsloading...
Last Post: Coding Exercise - SPOJ - 1417. University Employees - LUA programming
Next Post: Coding Exercise - LUA Programming - SPOJ Online Judge - 15711. Wow