Hacker News new | ask | show | jobs
by pbh101 3720 days ago
Going to echo this sentiment: I think the only way FizzBuzz is a trick question is if you aren't familiar with the modulus operator, in which case I think it fair to say you haven't spent much time programming.

That being said, I'm assuming the failure mode we're discussing is 'flailing at the whiteboard and would never make any progress given infinite time' and not 'wrote an off-by-one error that a unit test would catch.'

2 comments

Even if you've never heard of the modulus operator, it's still easy, eg in Python:

  fizz = 3
  buzz = 5
  both = 15

  for i in range(1, 101):
      if i == both:
          print "FizzBuzz"
          both += 15
          fizz += 3
          buzz += 5
      elif i == fizz:
          print "Fizz"
          fizz += 3
      elif i == buzz:
          print "Buzz"
          buzz += 5
      else:
          print i
If you can't write your own modulo function if don't understand the fundamentals of integer/floating point operations. Or are unaware of ceil and floor functions.