This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The Hilbert curve is a continuous curve that can be defined by recursion and completely fills a square in the limit n → ∞ . For illustration, the first three iterations of the Hilbert curve are shown here:
The n th Hilbert curve H n is a polygonal chain with 2 2 n vertices, all lying on a square grid. In each iteration step, an elementary square is split into four sub-squares. The vertex of a single square is P = ( x , y ) and there are two vectors U = ( u x , u y ) and V = ( v x , v y ) that span the square. The vector U is the connection vector to the vertex of the following square. This square is divided into four sub-squares each having a vertex P i and the vectors U i and V i ( i = 1 , 2 , 3 . 4 ). This is done according to the following scheme: In algebraic form this yields P 1 P 2 P 3 P 4 = P , = P + 2 1 V , = P + 2 1 ( U + V ) = P + U + 2 1 V U 1 U 2 U 3 U 4 = 2 1 V , = 2 1 U , = 2 1 U , = − 2 1 V , V 1 V 2 V 3 V 4 = 2 1 U = 2 1 V = 2 1 V = − 2 1 U Note, that the sum of the connection vectors U 1 + U 2 + U 3 + U 4 = U returns the original vector, so that the following squares correctly connect with the previous ones. If one hangs all connection vectors one after the other, one obtains the Hilbert curve of the current iteration step.
If we interpreted the underlying grid of squares as a picture with 2 n × 2 n pixels, the Hilbert curve gives us a way to iterate over all the pixels in the image. If you then arrange these pixels line by line in the order in which they were traversed by the Hilbert curve, the result is a new image. In this way, information can be encoded and decoded.
In our case, the image has 2 5 6 × 2 5 6 pixels, so we need the Hilbert curve H 8 to traverse all the pixels. The fact that the image is actually arranged in the form of a Hilbert curve can be seen in the rectangular structures. By trial and error one finds that the start and end point of the Hilbert curve lie respectively in the left and right lower corner of the image. If we transform our image according to the same scheme as above, the following text results:
This is the well-known Diophantus's riddle. Let D be the age of Diophantus in years, then it follows ⇒ ⇒ ⇒ 6 D + 1 2 D + 7 D + 5 + 2 D + 4 2 8 2 5 D + 9 9 D = D = D = 2 8 3 D = 9 ⋅ 3 2 8 = 8 4 Thus, 84 is the correct answer.
The following Python program converts the image into readable text. The function
hilbert
generates the Hilbert curve according to the recursion shown above and returns a list of points connected in series giving the Hilbert curve. The vectors P , U and V and the returned points are represented as complex numbers. The recursion automatically stops when the side length of the elemental squares is only 1.