forked from ociule/codeeval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz.py2
More file actions
35 lines (30 loc) · 747 Bytes
/
fizzbuzz.py2
File metadata and controls
35 lines (30 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys, doctest
def fizzbuzz(a, b, n):
"""
>>> fizzbuzz(3, 5, 10)
'1 2 F 4 B F 7 8 F B'
>>> fizzbuzz(2, 7, 15)
'1 F 3 F 5 F B F 9 F 11 F 13 FB 15'
"""
out = []
for i in range(1, n + 1):
if i % a == 0 and i % b == 0:
out.append("FB")
elif i % a == 0:
out.append("F")
elif i % b == 0:
out.append("B")
else:
out.append(str(i))
return " ".join(out)
def main():
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
l = map(int, test.split())
n, b, a = l.pop(), l.pop(), l.pop()
print fizzbuzz(a, b, n)
test_cases.close()
if len(sys.argv) == 1:
doctest.testmod()
else:
main()