Re:The Coding Interview
by georgieporgie on Wednesday October 05, 2011 @11:18AM
(#3075996)
someone who can write FizzBuzz in functional and OOP would be better.
How would you write an OOP implementation of FizzBuzz? I genuinely don't see how this would be done, short of something really contrived like fizz.Print(), buzz.print().
It would definitely be contrived. Let's see how contrived! ;)
class FizzBuzzer():
def __init__(self, num):
self.mod3 = num % 3 == 0
self.mod5 = num % 5 == 0
def check(self):
s = ""
if self.mod3:
s += "Fizz"
if self.mod5:
s += "Buzz"
print s
def main():
buzzer = FizzBuzzer(n)
buzzer.check()
Yeah, that's really contrived. Still, you display a familiarity with encapsulation, objects & their attributes/methods, etc.
Someone who barely scrapes out an imperative-style FizzBuzz might not be ideal. On the other hand, someone who can write FizzBuzz in functional and OOP would be better.
Even better would be someone who writes FizzBuzz with a poor order of growth, then explains why the order of growth sucks. That would demonstrate an understanding of algorithmic complexity.
I wonder if anyone looks for this when hiring.