Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2012 13:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/usr/bin/env python3
# micolous' implementation of fizzbuzz ;) (python2.6, 3.3 compat)
from __future__ import print_function
# setup a table of all the possible divisors (z)
z = {5: 'buzz', 3: 'fizz'}
# iterate through possible numbers (1 - 14) and populate that table with
# the other possible divisors <15: 6, 9, 10, 12. can use "any" on the
# iterator here as every result of this is bool() == False (False, None)
any((x % y == 0 and z.__setitem__(x, z[y])) for y in list(z.keys()) for x in range(1, 15))
# make the "fizzbuzz" entry for 15
z[0] = z[3] + z[5]
# modulus 15 the number and match it against the lookup dict (z), if it is not
# in the array return x. use any() here as it will continue hitting the
# generator to the end as print always returns None.
any(print(z.get(x % 15, x)) for x in range(1, 101))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment