Created
April 24, 2013 21:16
-
-
Save maltzsama/5455648 to your computer and use it in GitHub Desktop.
Fizz Buzz
Challenge Description: Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by 'A' e.g. three is replaced by the word fizz and any divisible by 'B' e.g. five by the word buzz. Numbers divisible by both become fizz b…
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| if (len(sys.argv) >= 2): | |
| fi = open(sys.argv[1], 'r') | |
| for i, n in enumerate(fi.readlines()): | |
| x = n.rstrip() | |
| lists = x.split() | |
| initSequence = [] | |
| for idx in range(1, int(lists[2])+1): | |
| mod1 = idx % int(lists[0]) | |
| mod2 = idx % int(lists[1]) | |
| if (mod1 != 0) and (mod2 != 0): | |
| initSequence.append(str(idx)) | |
| elif (mod1 == 0) and (mod2 == 0): | |
| initSequence.append("FB") | |
| elif (mod1 == 0): | |
| initSequence.append("F") | |
| else: | |
| initSequence.append("B") | |
| print ' '.join(initSequence) | |
| fi.close() | |
| else: | |
| print "Cant find a entry" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment