Coding Exercise – SPOJ – 1417. University Employees – LUA programming


This problem [here] is a tutorial for beginners. I am using this to practise my LUA skills.

You can submit the solution to SPOJ in LUA programming language.

emp Coding Exercise - SPOJ - 1417. University Employees - LUA programming beginner code implementation LUA programming language SPOJ online judge

Almost every decent programmers will know the solution in seconds. The answer is A+B. It will be 3 lines of code for most programming languages, but for LUA, there is no string splitting function inbuilt for use, so you have to come up one. Split the string into two numbers and add them, how simple is  that!

1
2
3
4
5
6
7
8
9
10
function split(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match);
    end
    return result;
end
 
a = split(io.read(), ' ')
print(tonumber(a[1]) + tonumber(a[2]))
function split(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match);
    end
    return result;
end

a = split(io.read(), ' ')
print(tonumber(a[1]) + tonumber(a[2]))

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
215 words
Last Post: Fasthosts Disable My website because WordPress sending too many emails due to spam comments
Next Post: Coding Exercise - LUA Programming - SPOJ Online Judge - 15710. Iterated sums

The Permanent URL is: Coding Exercise – SPOJ – 1417. University Employees – LUA programming

Leave a Reply