4 ms·
I could actually see myself botching fizzbuzz if I had been given it during the first 10 years of my career. Up until that point it had never occurred to me th
by tzs 6y ago
I could actually see myself botching fizzbuzz if I had been given it during the first 10 years of my career.
Up until that point it had never occurred to me that someone might apply for a programming job who could not write the simplest programs. Thus it would never have occurred to me that someone asking me such a simple question just wanted to see the obvious simple answer.
I'd have assumed they wanted me to use as much of the language as I could. So if they asked me to do it in Python, for example, I'd have tried for something like this:
def fizzbuzz(n, *args):
cur = ['' for x in range(1,n+1)]
for m, postfix in args:
cur = [y+postfix if x%m==0 else y for x, y in zip(range(1,n+1), cur)]
cur = [str(x) if y == '' else y for x, y in zip(range(1,n+1), cur)]
return cur
print("\n".join(fizzbuzz(100, (3, 'fizz'), (5, 'buzz'))))
...and since Python is not one of my main languages there is a good chance I'd botch it.