Adding solution for problem 6 in lua.