Solve problem 39 using Lua.