Skip to content

Instantly share code, notes, and snippets.

@theladyjaye
Created August 3, 2012 14:13
Show Gist options
  • Save theladyjaye/3248004 to your computer and use it in GitHub Desktop.
Save theladyjaye/3248004 to your computer and use it in GitHub Desktop.
Functional-ish fizzbuzz in python
from itertools import cycle, izip
import operator import add
fizz = cycle(['', '', 'fizz'])
buzz = cycle(['','','','','buzz'])
r = izip(fizz, buzz)
index = 1
while index < 101:
print("{}: {}".format(index, add(*r.next())))
index = index + 1
@mycoalshoe
Copy link

oops wrong language :)

@theladyjaye
Copy link
Author

Here it is in Haskell

let fizz = cycle ['', '', 'fizz']
let buzz = cycle ['', '', '', '', 'buzz']
let fizzbuzz = zipWith (++) fizz buzz
putStr (unlines fizzbuzz)

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