unravel
Ever wonder exactly how badly a naïve Fibonacci calculator performs? Something like the following Py’let:
F=lambda n:n<3 or F(n-1)+F(n-2)
[... yes, it's bad manners to code like this.]
No surprises for the algorithmically-competent, but it turns out that calculating F(n) results in 2×F(n)-1 calls to the function F.
I giggled.
Comments (2)
July 31st, 2009 at 4:18 pm
I like to think one gets extra style points for including “<3" in the code.
August 4th, 2009 at 6:26 pm
If only I had copypasta’d my pathologically concise code into a sufficiently romantic code editor!