3 ms·
Thank you for inspiring me! I revisited my FizzBuzz just now and threw together this obscene Python one-liner. (If I write this kind of code in production, I
by enceladus 15y ago
Thank you for inspiring me!
I revisited my FizzBuzz just now and threw together this obscene Python one-liner.
(If I write this kind of code in production, I should be a guaranteed "no-hire"!)
from itertools import chain, combinations
fizzbuzz = lambda n,terms: ((lambda d: d.update((x%d,w) for d,w in sorted(reduce(lambda (d0,w0),(d1,w1):(d0*d1,w0+w1),sorted(x)) for x in chain(*(combinations(terms.iteritems(),s) for s in xrange(1,len(terms)+1))))) or d)({0:str(x)})[0] for x in xrange(1,n))
print ', '.join(fizzbuzz(100,{3:'fizz',5:'buzz'}))