In geometry, the Peano curve is the first example of a space-filling curve to be discovered, by Giuseppe Peano in 1890. Peano's curve is a surjective, continuous function from the unit interval onto the unit square, however it is not injective. Peano was motivated by an earlier result of Georg Cantor that these two sets have the same cardinality. Because of this example, some authors use the phrase "Peano curve" to refer more generally to any space-filling curve.
The program takes an input which is an integer
n, and outputs a drawing representing the
nth iteration of the Peano curve, starting from the sideways 2 shown in the leftmost part of this image:
n giving the iteration number of the Peano curve.
Optional, additional input is described in the bonuses section.
A drawing of the
nth iteration of the Peano curve. The drawing can be both ASCII art or a "real" drawing, whichever is easiest or shortest.
- The input and output can be given in any convenient format (choose the most appropriate format for your language/solution).
- No need to handle negative values or invalid input
- Either a full program or a function are acceptable.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Since this shouldn't be a walk in the park (at least in most languages I can think of), bonus points are awarded for the following:
- -100 bytes if your code generates a gif of the construction of the Peano curves up to
- -100 bytes if your code draws a space-filling curve for any rectangular shape (the Peano curve only works for squares, obviously). You can assume that the input then takes on the form
n l wwhere
nhas the same meaning as before (the number of the iteration), but where
wbecome the length and width of the rectangle in which to draw the curve. If
l == w, this becomes the regular Peano curve.
Negative scores are allowed (but are they possible...).
Please include the output of your program in the solution for
n == 3 (l == w == 1).
nbe used for if
ware also inputs??????????? And would the Peano curve be a special case - it's not the only spacefilling curve, so some algorithms may have to specialcase it \$\endgroup\$