Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created October 5, 2012 18:23
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 ryancdotorg/3841505 to your computer and use it in GitHub Desktop.
Save ryancdotorg/3841505 to your computer and use it in GitHub Desktop.
Precomputed extended FizzBuzz in Python
#!/bin/env python
from collections import OrderedDict
substitutions = OrderedDict([(3, 'Fizz'), (5, 'Buzz'), (7, 'Quxx')])
max_i = 127
# Pre-compute all outputs - should be faster.
output_list = ['']*(max_i+1)
for n in substitutions.keys():
for i in xrange(0, max_i+1, n):
output_list[i] += substitutions[n]
for i in xrange(1, max_i+1):
print output_list[i] or i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment