I was thinking about recursion. The classic example of an elegant recursive algorithm is:
Recursive functions call themselves, eventually returning the correct answer.
I thought, why stop at the function level? I want to make it bigger - how about a whole program that calls itself -- and modifies itself? Of course, this would be really impractical in terms of memory, but it sounded like fun.
Big recursion
So, during my lunch at work, I put the following together. (C# 2.0)
If you run the program, it will compute a factorial for you... in a non-standard way.
Although this was fun, it wasn't extreme enough. I wanted something even bigger, more impractical, and more hacky. So, I invented "bigger" recursion. Have fun understanding what this next one does.
Even Bigger Recursion
(Warning: the following code will compile but is not guaranteed to work on your machine. It's extremely fragile, for reasons that will become clear. I used Visual Studio 2005 C# console app to build it.)
Hint 1: The byte 0xE2 is not commonly found in C# executables.
Hint 2: this is my directory listing after I run the program and find the factorial of 5:
Bigger2.exe
Bigger3.exe
Bigger4.exe
Bigger5.exe
BiggerRecursion.exe
BiggerRecursion.pdb
BiggerRecursion.vshost.exe