Here's a neat little (inefficient) trick: say I give you 8 types of puzzle pieces
then I can arbitrarily convert any number from base 4 into base 2! Don't believe me? Here's how: say you want to convert , what we should do is create an empty frame whose right side matches the number we need to transform in base 4:
and try to fill this frame out. It turns out that there's a unique way to fill this puzzle out, but after we're done, we can just read the type of the curve on the bottom of the puzzle to extract the base two representation:
notice that ! What sorcery is this?
In order to understand how this works, let's look at two operators. Let be the representation of , so for example and let be the binary representation , so It can be easily shown that and .
Hmmm, now things become a bit clearer. Consider an edge of a puzzle piece, say piece :
the horizontal edges are in reality functions that takes in the input , and produces for whatever that edge is displaying. So the top edge of piece G denotes the function and the bottom edge denotes the function . The vertical edges are symmetric w.r.t to
It turns out that each piece denotes functional equality between a and a . For example, the G piece says that .
Therefore, our original system is just but by placing down the D piece, we're basically claiming that because the D piece says that . Because of this equality, we can also see that when we look at the final solution, no matter what path we take, the composition of all of the edges will all be the same function! With a little bit more analysis, we can derive nice properties about this system: each of the jigsaw piece is uniquely determined by the top and right edges and each puzzle has a unique solution, and it is the same solution such that all of the downward arrows are zeros, because the right-ward arrows composes only base 2 numbers. Therefore, our system basically reduces to a rewrite system on the language of and we seek a final form (a normal form if you will) where the downward arrows are all zeros.
Finally, we can now compute this via dynamic programming: notice that we only need to have the top and the right edge curves in order to uniquely determine the next piece. This means that we can progressively reduce our system into the normal form by zig-zagging: