Yes, which is why when I would ask it of a someone who calls themselves a senior programmer I was dumbfounded at how many could not answer the question.
But for FizzBuzz I explain the problem, explain that there is no trick and the simplest answer that produces the correct output will be fine. To solve it you need to know about building a loop, what the mod operator does, and maybe keeping state depending on how you build it. I tell them to write it in the language they know best. None of those things should be "gotchas" in your favorite language.
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.Because it was an unconventional solution, the interviewer didn't like it.
Wie waere es fuer dich, wenn ich in einer Sprache antworte, die du wahrscheinlich nicht verstehst?