Skip to content

Instantly share code, notes, and snippets.

@kbob
Created November 22, 2012 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbob/4133330 to your computer and use it in GitHub Desktop.
Save kbob/4133330 to your computer and use it in GitHub Desktop.
FizzBuzz
#!/usr/bin/python
from itertools import count, cycle, islice, izip, repeat
def fizzbuzz(n):
class d(int): __add__ = lambda self, other: other
def i(x): return x
def f(x): return x + 'Fizz'
def b(x): return x + 'Buzz'
def p(x): print x
def a(x, f): return x and f(x) or f
[reduce(a, i) for i in islice(izip(count(1),
repeat(d),
cycle((i, i, f)),
cycle([i, i, i, i, b]),
repeat(p)),
n)]
fizzbuzz(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment