13
1
Introduction
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.
Challenge
The program takes an input which is an integer n
, and outputs a drawing representing the n
th iteration of the Peano curve, starting from the sideways 2 shown in the leftmost part of this image:
Input
An integer n
giving the iteration number of the Peano curve.
Optional, additional input is described in the bonuses section.
Output
A drawing of the n
th iteration of the Peano curve. The drawing can be both ASCII art or a "real" drawing, whichever is easiest or shortest.
Rules
- 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.
Bonuses
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
n
. - -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 w
wheren
has the same meaning as before (the number of the iteration), but wherel
andw
become the length and width of the rectangle in which to draw the curve. Ifl == w
, this becomes the regular Peano curve.
Negative scores are allowed (but are they possible...).
Edit
Please include the output of your program in the solution for n == 3 (l == w == 1)
.
1Welcome to PPCG :) This, at a glance, looks like a nice first challenge. Although it feels familiar, I think the challenge I might be thinking of was an ASCII art one. Note, though, that we strongly discourage bonuses and that there will be golfing languages that can achieve this in less than 100 bytes. Also, and most importantly, you need a winning criterion. Given that your bonuses subtract bytes from a solution's score, I suspect you intend this to be [tag:code-golf]. – Shaggy – 2018-11-17T23:43:30.583
I think you're probably confusing it with either a question about Hilbert curves, which are sort of an easier version of Peano curves, or one of the many questions about fractals, mainly the Koch snowflake and Sierpinski carpet. As for the bonuses, I seriously doubt that there would be golfing languages that can do this in less than 100 bytes... And my winning criterion is included, it's the last point in the "Rules" section :). – Peiffap – 2018-11-17T23:47:07.673
Have you seen golfing languages on this site? I’m willing to bet Canvas can do it in less than 50. – Quintec – 2018-11-18T00:01:12.530
Oh, I could well be thinking of a challenge about a different (but maybe similar looking pattern), which is why I didn't VTC this as a dupe - that and my vote is a hammer, so I avoid using it unless I'm 100% sure a challenge is a dupe. And apologies for missing the winning criterion; my brain must have trained itself to gloss over the boilerplate rules section of a challenge! I was looking for the winning condition in the tags. – Shaggy – 2018-11-18T00:01:19.633
I added the criterion to the tags, and removed one of the less interesting ones ;). I know the question itself shouldn't be that hard to solve, but I doubt the golfing languages can generate gifs easily. I could remove the bonuses, but then how do I motivate people to still try to complete those tasks? – Peiffap – 2018-11-18T00:07:30.617
Our mere presence on this SE is motivation enough for us to complete challenges! ;) – Shaggy – 2018-11-18T00:54:53.153
4Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs – ASCII-only – 2018-11-18T01:46:04.553
2Oh also what would
n
be used for ifl
andw
are 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 – ASCII-only – 2018-11-18T02:03:41.2332Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions – ASCII-only – 2018-11-18T02:11:07.830
7Bonuses in code golf is one of the most agreed-upon things to avoid when writing challenges. I suggest you remove them and decide which is to be the canonical version of the challenge. – lirtosiast – 2018-11-18T05:14:57.103
Is that OK if the output is mirrored horizontally and/or vertically? – Arnauld – 2018-11-18T11:27:35.510
@Arnauld Yes, that's alright – Peiffap – 2018-11-18T11:28:27.563
Even if you're going to keep the bonises, please address this comment. Which curve sd be used for retangulr outpt?
– user202729 – 2018-11-18T11:49:58.067A continuous space-filling curve which looks like the Peano curve while covering the rectangle. If it does this, it's acceptable output. – Peiffap – 2018-11-18T11:54:21.053
@ASCII-only A true "space filling curve" is the continuous function that is the limit of such drawings (its own drawing would just be a solid black rectangle), and you cannot actually get a continuous function in the limit from zigzagging. – Ørjan Johansen – 2018-11-19T02:36:45.533
Are we allowed to draw it upside down? – LiefdeWen – 2018-11-19T14:07:44.653
Sure! @LiefdeWen – Peiffap – 2018-11-19T15:20:14.590