Created
September 16, 2011 10:40
-
-
Save kk6/1221822 to your computer and use it in GitHub Desktop.
無駄にitertoolsを駆使したFizzBuzz(Python3では動きません)
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
#-*- coding:utf8 -*- | |
# 無駄にitertoolsを駆使したFizzBuzz | |
from itertools import repeat, ifilterfalse, starmap, count | |
N = 31 | |
LEN = range(1, N) | |
FIZZ, BUZZ = map(repeat, ("Fizz", "Buzz")) | |
fizz, buzz = ( | |
map(list, | |
starmap(ifilterfalse, | |
[(lambda i: i%3, LEN), (lambda i: i%5, LEN)]))) | |
fizz, buzz = starmap(map, | |
[(lambda i: i in fizz, LEN), (lambda i: i in buzz, LEN)]) | |
fizz, buzz = starmap(zip, | |
[(fizz, FIZZ), (buzz, BUZZ)]) | |
fizz, buzz = starmap(starmap, | |
[(lambda x, y: x * y, fizz), (lambda x, y: x * y, buzz)]) | |
fizzbuzz = starmap(lambda x, y: x + y, zip(fizz, buzz)) | |
print(' '.join([(item or str(i)) for i, item in zip(count(1), fizzbuzz)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pythonならホントはワンライナーで書けるけど敢えてitertools縛りで。