This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,3 +1,7 @@
for i in range(1, 101):
words = [word for n, word in ((3, 'Fizz'), (5, 'Buzz')) if not i % n]
print ''.join(words) or i
for n in range(1,101):
msg = ""
if not (n%3):
msg += "Fizz"
if not (n%5):
msg += "Buzz"
print msg or str(n)

View file

@ -1,4 +1,3 @@
print ('\n'.join(''.join(''.join(['' if i%3 else 'Fizz',
'' if i%5 else 'Buzz'])
or str(i))
for i in range(1,101)))
for i in range(1, 101):
words = [word for n, word in ((3, 'Fizz'), (5, 'Buzz')) if not i % n]
print ''.join(words) or i

View file

@ -1,2 +1,4 @@
for i in range(1, 101):
print 'Fizz'*(not(i%3))+'Buzz'*(not(i%5)) or i
print ('\n'.join(''.join(''.join(['' if i%3 else 'Fizz',
'' if i%5 else 'Buzz'])
or str(i))
for i in range(1,101)))

View file

@ -1,6 +1,2 @@
messages = [None, "Fizz", "Buzz", "FizzBuzz"]
acc = 810092048
for i in xrange(1, 101):
c = acc & 3
print messages[c] if c else i
acc = acc >> 2 | c << 28
for i in range(1, 101):
print 'Fizz'*(not(i%3))+'Buzz'*(not(i%5)) or i

View file

@ -1,14 +1,6 @@
>>> ' '.join(''.join(''.join(['' if i%3 else 'F',
'' if i%5 else 'B'])
or str('00'))
for i in range(1,16))
'00 00 F 00 B F 00 00 F B 00 F 00 00 FB'
>>> _
'00 00 F 00 B F 00 00 F B 00 F 00 00 FB'
>>> _.replace('FB','11').replace('F','01').replace('B','10').split()[::-1]
['11', '00', '00', '01', '00', '10', '01', '00', '00', '01', '10', '00', '01', '00', '00']
>>> '0b' + ''.join(_)
'0b110000010010010000011000010000'
>>> eval(_)
810092048
>>>
messages = [None, "Fizz", "Buzz", "FizzBuzz"]
acc = 810092048
for i in xrange(1, 101):
c = acc & 3
print messages[c] if c else i
acc = acc >> 2 | c << 28

View file

@ -1,6 +1,14 @@
import random
for i in range(0, 100):
if not i % 15:
random.seed(1178741599)
print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)]
>>> ' '.join(''.join(''.join(['' if i%3 else 'F',
'' if i%5 else 'B'])
or str('00'))
for i in range(1,16))
'00 00 F 00 B F 00 00 F B 00 F 00 00 FB'
>>> _
'00 00 F 00 B F 00 00 F B 00 F 00 00 FB'
>>> _.replace('FB','11').replace('F','01').replace('B','10').split()[::-1]
['11', '00', '00', '01', '00', '10', '01', '00', '00', '01', '10', '00', '01', '00', '00']
>>> '0b' + ''.join(_)
'0b110000010010010000011000010000'
>>> eval(_)
810092048
>>>

View file

@ -1,13 +1,6 @@
from itertools import cycle, izip, count, islice
import random
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# print the first 100
for i in islice(fizzbuzz, 100):
print i
for i in range(0, 100):
if not i % 15:
random.seed(1178741599)
print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)]

View file

@ -0,0 +1,13 @@
from itertools import cycle, izip, count, islice
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# print the first 100
for i in islice(fizzbuzz, 100):
print i