I can write Fizzbuzz (sort of)
This refers to A post on codinghorror.com.
I needed around 6 minutes, 40 seconds to implement a correct solution in Python..
I had a near-solution more quickly, using print()
with a trailing comma, but it
printed „Fizz Buzz“, not „FizzBuzz“. The reason is that print()
with a trailing
comma nevertheless adds a space to the printed string, for whatever reasons. So
I had to google and fix this, by using sys.stdout.write()
instead of print()
.
In my opinion that just shows the problem: You program and then some minor, but critical problem comes up and this is where your time goes. But no one honors that, they just say „He’s a slow programmer.“
So, with nearly seven minutes, am I a good programmer or not? Would you even consider to hire me?
Addendum: Checking closely, I found that the program prints results for 1 to 99,
so in a strict sense it’s wrong. I had used range(1,100)
, which only prints up
to 99. So, my solution was not even correct. Now I’m
quite sure you won’t hire me. Especially if you’re Joel Spolsky or one of those
other super-picky employers out there.
Here’s my solution (the wrong one that omits 100):
#!/usr/bin/env python import sys for i in range(1, 100): fizzorbuzz = False if i % 3 == 0: sys.stdout.write('Fizz') fizzorbuzz = True if i % 5 == 0: sys.stdout.write('Buzz') fizzorbuzz = True if not fizzorbuzz: sys.stdout.write(str(i)) print