Last active
August 29, 2015 13:59
-
-
Save kainz/10506786 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"\n".join([ ":".join([str(c[0]), "".join([ c[1][i] for i in filter(lambda t: c[0] % t == 0,c[1].keys() ) ]) ]) for c in [ (x, {3: 'Fizz', 5: 'Buzz'}) for x in range(100) ] ]) | |
# to make it even worse | |
[ ":".join((str(n), re.sub(r'^((?:Fizz|Buzz){0,2}).+$', r'\1', reduce(lambda i, a: re.sub(r'((?<!x)(x{{{0}}})+(?!x))$'.format(a[0]),r'{}\1'.format(a[1]), i), ( (3, 'Fizz'), (5, 'Buzz') ) , 'x' * n )), )) for n in xrange(100) ] | |
# Still tricky, but not nearly so horrible | |
[ (x, "".join([ v for k,v in {3: 'Fizz', 5: 'Buzz'}.iteritems() if x % k == 0 ])) for x in range(100)] | |
Why are these so horrible? Well, number two is a classic example I think of mistyping. Namely, we are generating a flat string then using a parameterized regex as a DFA to mutate the string into an annotated state, then using a final regex to separate the structure once again (if you could call it thath). | |
Number one is also horrible, though seemingly shorter, because it combines multiple hard-to-parse features of Python into a single line. Namely, we abuse scoping and parenthitical rules generate a series of tabular inputs to a test. | |
Number three is tricky but not nearly as horrible, because proper list comprehension guard syntax and array unpacking is used to generate the same output, so we actually use a minimum number of constructs in this case. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment