Last active
December 19, 2015 12:59
-
-
Save alexpirine/5959159 to your computer and use it in GitHub Desktop.
FizzBuzz
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
# 1 min 20 s (including login and tests) | |
for k in range(1, 101): | |
if not k % 3 and not k % 5: | |
print "FizzBuzz" | |
elif not k % 3: | |
print "Fizz" | |
elif not k % 5: | |
print "Buzz" | |
else: | |
print k | |
# 15 min (after several trials, trying to avoid code redundancy) | |
for k in range(1, 101): | |
l = '%d' % k | |
r = [{0: 'Fizz'}.get(k % 3, l), {0: 'Buzz'}.get(k % 5, l)] | |
if l in r: | |
r.remove(l) | |
print ''.join(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment