Pages

Friday, August 26, 2011

More Quining, Recursion, and Fractals.

I worked on the short quine I posted this morning a bit, and added some stuff to it. A while ago I was playing around with adjacency matrices, and noticed that the adjacency matrix for n-dimensional hypercubes looks kind of like a fractal the higher n gets. It also turns out you can very easily create the matrix recursively from knowing just the one for dimension n=2, which looks like this:
Black represents a one, white a zero.

If we look at the matrix for n=3 (lines added for clarity):
we notice that this is simply twice the n=2 matrix (diagonally), with the other two quarters filled in by identity matrices.
This trend continues for higher dimensions:
n=4


n=5

And so on.

It seems obvious to use recursion to compute these matrices, so I thought this would be neat to implement into a program that is already self-replicating - a quine. So here's what my program does:
  • It creates a bitmap of the adjacency matrix for n=2
  • It creates and then executes new script with nearly identical source code, but this code returns the n=3 hypercube adjacency matrix, calculated recursively
  • This continues until dimension 10 (after that the recursion to compute the next matrix loops for quite long, not sure how/if I will fix this), after which the program and all that of the "children" it created exit.


if you want to try it out yourself, here's the code.








No comments: