Created
October 5, 2012 18:23
-
-
Save ryancdotorg/3841505 to your computer and use it in GitHub Desktop.
Precomputed extended FizzBuzz in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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