Created
September 23, 2018 17:58
-
-
Save jamesoff/9bcab19e4e4d19ff6846da948ea27936 to your computer and use it in GitHub Desktop.
fizzbuzz without comparison operator
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
""" | |
fizzbuzz.py | |
Implement fizzbuzz without using a comparison operator. | |
Because I said I could. | |
""" | |
import sys | |
def horrible_loop(): | |
# use 3 and 5 not 2 and 4 because range() is 0-indexed | |
three_counter = 3 | |
five_counter = 5 | |
for i in range(100): | |
output = "" | |
try: | |
discard = 1 / three_counter | |
three_counter -= 1 | |
except: | |
three_counter = 2 | |
output = "Fizz" | |
try: | |
discard = 1 / five_counter | |
five_counter -= 1 | |
except: | |
five_counter = 4 | |
output += "Buzz" | |
try: | |
discard = 1 / len(output) | |
print output | |
except: | |
print str(i) | |
def main(): | |
horrible_loop() | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment