![]() |
Binary Chops I recently found a nice exercise from Dave Thomas, namely to look for inventive ways of writing a classic binary chop. My favorite language is Common Lisp (although I'm paid to write Java), so that's what I decided to use. The obvious iterative and recursive solutions took me about five minutes each, but what would I do for something inventive? Here's what I came up with. Rather than iterating or recursing, this solution constructs a new (anonymous) function at each chop, with each function evaluating to the next function. Finally, the last function evaluates to the required answer.
I'm not sure what Dave and friends would make of this solution - it's certainly not pragmatic in any way! It was a lot of fun to write though. |