Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Created April 24, 2013 21:16
Show Gist options
  • Select an option

  • Save maltzsama/5455648 to your computer and use it in GitHub Desktop.

Select an option

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…
#!/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