Skip to content

Instantly share code, notes, and snippets.

@reikoNeko
Last active September 14, 2017 00:59
Show Gist options
  • Save reikoNeko/b30d671f6f167ec06086d6208e5b2e93 to your computer and use it in GitHub Desktop.
Save reikoNeko/b30d671f6f167ec06086d6208e5b2e93 to your computer and use it in GitHub Desktop.
A clear but not fully pythonic fizzbuzz implementation
def fizzbuzz(n):
for x in range(1,n+1):
result=''
if not x%3: result += ('fizz')
if not x%5: result += ('buzz')
yield result if result else str(x)
@reikoNeko
Copy link
Author

reikoNeko commented Sep 13, 2017

This all grew out of a thread on the mailing list for the Philadelphia Linux User Group about https://blog.codinghorror.com/why-cant-programmers-program

And this was before I read https://blog.codinghorror.com/fizzbuzz-the-programmers-stairway-to-heaven/

The whole point of the original article was to think about why we have to ask people to write FizzBuzz. The mechanical part of writing and solving FizzBuzz, however cleverly, is irrelevant. Any programmer who cares enough to read programming blogs is already far beyond such a simple problem. FizzBuzz isn't meant for us. It's the ones we can't reach – the programmers who don't read anything – that we're forced to give the FizzBuzz test to.

C'est la vim.

@wirewc
Copy link

wirewc commented Sep 13, 2017

Your last iteration of FizzBuzz was actually something worth checking out. Excellent use of a generator in a unique and compact manner. Not sure if you want to go to production with that code but you go girl!

@reikoNeko
Copy link
Author

In production I'd cheat more and also consider memoization. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment