|
You don't need mod, loops or recursion to solve it. For instance: local remove = table.remove
local insert = table.insert
local print = print
local sequence = {
false , false , 'Fizz' , false , 'Buzz',
'Fizz' , false , false , 'Fizz' , 'Buzz' ,
false , 'Fizz' , false , false , 'FizzBuzz'
}
local function o(v)
local name = remove(sequence,1)
insert(sequence,name)
print(name or v)
return v + 1
end
local function t(v)
return o(o(o(o(o(o(o(o(o(o(v))))))))))
end
local function h(v)
t(t(t(t(t(t(t(t(t(t(v))))))))))
end
h(1)
It does rely upon state (the sequence table) but even that could probably be worked around if Lua had a slice syntax. |
Although we could debate that the way you call o and t is just you manually expanding a loop. In which case I would question why you didn't just use a loop. :)
I could also debate with you that you had to at least understand what mod is to build the sequence.
I would also give you bonus points for detecting that it is a repeating pattern.
But the point is, you solved it, you wrote code that could solve it. So now I know that you're at least capable of writing basic code, and we've got a couple of things to talk about!