Drawing the Peano curve
up vote
13
down vote
favorite
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)
.
code-golf ascii-art graphical-output geometry fractal
|
show 12 more comments
up vote
13
down vote
favorite
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)
.
code-golf ascii-art graphical-output geometry fractal
1
Welcome 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 code-golf.
– Shaggy
Nov 17 at 23:43
4
Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs
– ASCII-only
Nov 18 at 1:46
2
Oh also what wouldn
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
Nov 18 at 2:03
2
Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions
– ASCII-only
Nov 18 at 2:11
7
Bonuses 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
Nov 18 at 5:14
|
show 12 more comments
up vote
13
down vote
favorite
up vote
13
down vote
favorite
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)
.
code-golf ascii-art graphical-output geometry fractal
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)
.
code-golf ascii-art graphical-output geometry fractal
code-golf ascii-art graphical-output geometry fractal
edited Nov 18 at 0:04
asked Nov 17 at 23:18
Peiffap
776
776
1
Welcome 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 code-golf.
– Shaggy
Nov 17 at 23:43
4
Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs
– ASCII-only
Nov 18 at 1:46
2
Oh also what wouldn
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
Nov 18 at 2:03
2
Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions
– ASCII-only
Nov 18 at 2:11
7
Bonuses 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
Nov 18 at 5:14
|
show 12 more comments
1
Welcome 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 code-golf.
– Shaggy
Nov 17 at 23:43
4
Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs
– ASCII-only
Nov 18 at 1:46
2
Oh also what wouldn
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
Nov 18 at 2:03
2
Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions
– ASCII-only
Nov 18 at 2:11
7
Bonuses 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
Nov 18 at 5:14
1
1
Welcome 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 code-golf.
– Shaggy
Nov 17 at 23:43
Welcome 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 code-golf.
– Shaggy
Nov 17 at 23:43
4
4
Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs
– ASCII-only
Nov 18 at 1:46
Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs
– ASCII-only
Nov 18 at 1:46
2
2
Oh also what would
n
be used for if l
and w
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
Nov 18 at 2:03
Oh also what would
n
be used for if l
and w
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
Nov 18 at 2:03
2
2
Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions
– ASCII-only
Nov 18 at 2:11
Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions
– ASCII-only
Nov 18 at 2:11
7
7
Bonuses 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
Nov 18 at 5:14
Bonuses 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
Nov 18 at 5:14
|
show 12 more comments
9 Answers
9
active
oldest
votes
up vote
4
down vote
accepted
Mathematica, score 60 - 100 - 100 = -140
Graphics[PeanoCurve@a~Reverse~3~Scale~#2]~Animate~{a,1,#,1}&
Pure function. Takes n
and {l, w}
(width and height) as input, and gives an animated graphic as output. It first creates a nth order Peano curve with PeanoCurve
. Since the l = w case still needs to create a Peano curve, we flip the expression at level 3, similar to DavidC's answer; for l ≠ w, we just Scale
the curve to the rectangle. This curve will still be space-filling, satisfying the second bonus. For the first bonus, we just Animate
it over all sizes. Note that OP suggested that this was sufficiently different from DavidC's to warrant its own answer. The result for n = 3, l = w = 1 is as follows:
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
add a comment |
up vote
12
down vote
GFA Basic 3.51 (Atari ST), 156 134 124 bytes
A manually edited listing in .LST format. All lines end with CR
, including the last one.
PRO f(n)
DR "MA0,199"
p(n,90)
RET
PRO p(n,a)
I n
n=n-.5
DR "RT",a
p(n,-a)
DR "FD4"
p(n,a)
DR "FD4"
p(n,-a)
DR "LT",a
EN
RET
Expanded and commented
PROCEDURE f(n) ! main procedure, taking the number 'n' of iterations
DRAW "MA0,199" ! move the pen to absolute position (0, 199)
p(n,90) ! initial call to 'p' with 'a' = +90
RETURN ! end of procedure
PROCEDURE p(n,a) ! recursive procedure taking 'n' and the angle 'a'
IF n ! if 'n' is not equal to 0:
n=n-0.5 ! subtract 0.5 from 'n'
DRAW "RT",a ! right turn of 'a' degrees
p(n,-a) ! recursive call with '-a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,a) ! recursive call with 'a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,-a) ! recursive call with '-a'
DRAW "LT",a ! left turn of 'a' degrees
ENDIF ! end
RETURN ! end of procedure
Example output
add a comment |
up vote
10
down vote
Perl 6, 117 bytes
{map ->y{|map {(((++$+y)%2+$++)%3**(y+$^v,*/3...*%3)??$^s[$++%2]!!'│')xx$_*3},<┌ ┐>,$_,<└ ┘>,1},^$_}o*R**3
Try it online!
0-indexed. Returns a 2D array of Unicode characters. The basic idea is that for lower rows, the expression
(x + (x+y)%2) % (3 ** trailing_zeros_in_base3(3*(y+1)))
yields the pattern
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|................||........ % 9
..||....||....||....||....| % 3
|....||....||....||....||.. % 3
........||................| % 9
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|.......................... % 27
For upper rows, the expression is
(x + (x+y+1)%2) % (3 ** trailing_zeros_in_base3(3*(y+3**n)))
Explanation
{ ... }o*R**3 # Feed $_ = 3^n into block
map ->y{ ... },^$_ # Map y = 0..3^n-1
|map { ... },<┌ ┐>,$_,<└ ┘>,1 # Map pairs (('┌','┐'),3^n) for upper rows
# and (('└','┘'),1) for lower rows.
# Block takes items as s and v
( ... )xx$_*3 # Evaluate 3^(n+1) times, returning a list
(++$+y)%2 # (x+y+1)%2 for upper rows, (x+y)%2 for lower rows
( +$++) # Add x
(y+$^v,*/3...*%3) # Count trailing zeros of 3*(y+v) in base 3
3** # nth power of 3
% # Modulo
??$^s[$++%2] # If there's a remainder yield chars in s alternately
!!'│' # otherwise yield '│'
add a comment |
up vote
6
down vote
K (ngn/k), 37 27 26 bytes
{+y,(|'y:x,,>*x),x}/1,&2*
Try it online!
returns a boolean matrix
|'y
is syntax specific to ngn/k. other dialects require a :
to make an each-ed verb monadic: |:'y
1
To make the output more beautiful, highlight all occurences of1
(if supported by your browser)
– user202729
Nov 18 at 9:32
3
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
add a comment |
up vote
5
down vote
Wolfram Language 83 36 bytes, (possibly -48 bytes with bonus)
As of version 11.1, PeanoCurve
is a built-in.
My original, clumsy submission wasted many bytes on GeometricTransformation
and ReflectionTransform.
This much reduced version was suggested by alephalpha.
Reverse
was required to orient the output properly.
Graphics[Reverse/@#&/@PeanoCurve@#]&
Example 36 bytes
Graphics[Reverse/@#&/@PeanoCurve@#]&[3]
Bonus
If this qualifies for the 100 pt bonus, it weighs in at 52 - 100 = -48
The code [5]
was not counted, only the pure function.
Table[Graphics[Reverse/@#&/@PeanoCurve@#]&@k{k,#}&[5]
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
add a comment |
up vote
4
down vote
BBC BASIC, 142 ASCII characters (130 bytes tokenised)
Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html
I.m:q=FNh(m,8,8,0)END
DEFFNh(n,x,y,i)
IFn F.i=0TO8q=FNh(n-1,x-i MOD3MOD2*2*x,y-i DIV3MOD2*2*y,i)DRAWBY(1AND36/2^i)*x,y*(12653/3^i MOD3-1)N.
=0
add a comment |
up vote
4
down vote
HTML+SVG+JS, 224 213 bytes
The output is mirrored horizontally.
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
Try it online! (prints the HTML)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
add a comment |
up vote
3
down vote
Logo, 89 bytes
to p:n:a
if:n>0[rt:a
p:n-1 0-:a
fw 5
p:n-1:a
fw 5
p:n-1 0-:a
lt:a]end
to f:n
p:n*2 90
end
Port of @Arnauld's Atari BASIC answer. To use, do something like this:
reset
f 3
add a comment |
up vote
2
down vote
Stax, 19 bytes
∩▐j>♣←╙~◘∩╗╢a╘─Ràô
Run and debug it
Output for 3:
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
█ █ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ █ █
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
add a comment |
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Mathematica, score 60 - 100 - 100 = -140
Graphics[PeanoCurve@a~Reverse~3~Scale~#2]~Animate~{a,1,#,1}&
Pure function. Takes n
and {l, w}
(width and height) as input, and gives an animated graphic as output. It first creates a nth order Peano curve with PeanoCurve
. Since the l = w case still needs to create a Peano curve, we flip the expression at level 3, similar to DavidC's answer; for l ≠ w, we just Scale
the curve to the rectangle. This curve will still be space-filling, satisfying the second bonus. For the first bonus, we just Animate
it over all sizes. Note that OP suggested that this was sufficiently different from DavidC's to warrant its own answer. The result for n = 3, l = w = 1 is as follows:
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
add a comment |
up vote
4
down vote
accepted
Mathematica, score 60 - 100 - 100 = -140
Graphics[PeanoCurve@a~Reverse~3~Scale~#2]~Animate~{a,1,#,1}&
Pure function. Takes n
and {l, w}
(width and height) as input, and gives an animated graphic as output. It first creates a nth order Peano curve with PeanoCurve
. Since the l = w case still needs to create a Peano curve, we flip the expression at level 3, similar to DavidC's answer; for l ≠ w, we just Scale
the curve to the rectangle. This curve will still be space-filling, satisfying the second bonus. For the first bonus, we just Animate
it over all sizes. Note that OP suggested that this was sufficiently different from DavidC's to warrant its own answer. The result for n = 3, l = w = 1 is as follows:
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Mathematica, score 60 - 100 - 100 = -140
Graphics[PeanoCurve@a~Reverse~3~Scale~#2]~Animate~{a,1,#,1}&
Pure function. Takes n
and {l, w}
(width and height) as input, and gives an animated graphic as output. It first creates a nth order Peano curve with PeanoCurve
. Since the l = w case still needs to create a Peano curve, we flip the expression at level 3, similar to DavidC's answer; for l ≠ w, we just Scale
the curve to the rectangle. This curve will still be space-filling, satisfying the second bonus. For the first bonus, we just Animate
it over all sizes. Note that OP suggested that this was sufficiently different from DavidC's to warrant its own answer. The result for n = 3, l = w = 1 is as follows:
Mathematica, score 60 - 100 - 100 = -140
Graphics[PeanoCurve@a~Reverse~3~Scale~#2]~Animate~{a,1,#,1}&
Pure function. Takes n
and {l, w}
(width and height) as input, and gives an animated graphic as output. It first creates a nth order Peano curve with PeanoCurve
. Since the l = w case still needs to create a Peano curve, we flip the expression at level 3, similar to DavidC's answer; for l ≠ w, we just Scale
the curve to the rectangle. This curve will still be space-filling, satisfying the second bonus. For the first bonus, we just Animate
it over all sizes. Note that OP suggested that this was sufficiently different from DavidC's to warrant its own answer. The result for n = 3, l = w = 1 is as follows:
answered Nov 19 at 13:07
LegionMammal978
15k41752
15k41752
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
add a comment |
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
very nice! (with proper orientation too)
– DavidC
Nov 19 at 14:28
add a comment |
up vote
12
down vote
GFA Basic 3.51 (Atari ST), 156 134 124 bytes
A manually edited listing in .LST format. All lines end with CR
, including the last one.
PRO f(n)
DR "MA0,199"
p(n,90)
RET
PRO p(n,a)
I n
n=n-.5
DR "RT",a
p(n,-a)
DR "FD4"
p(n,a)
DR "FD4"
p(n,-a)
DR "LT",a
EN
RET
Expanded and commented
PROCEDURE f(n) ! main procedure, taking the number 'n' of iterations
DRAW "MA0,199" ! move the pen to absolute position (0, 199)
p(n,90) ! initial call to 'p' with 'a' = +90
RETURN ! end of procedure
PROCEDURE p(n,a) ! recursive procedure taking 'n' and the angle 'a'
IF n ! if 'n' is not equal to 0:
n=n-0.5 ! subtract 0.5 from 'n'
DRAW "RT",a ! right turn of 'a' degrees
p(n,-a) ! recursive call with '-a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,a) ! recursive call with 'a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,-a) ! recursive call with '-a'
DRAW "LT",a ! left turn of 'a' degrees
ENDIF ! end
RETURN ! end of procedure
Example output
add a comment |
up vote
12
down vote
GFA Basic 3.51 (Atari ST), 156 134 124 bytes
A manually edited listing in .LST format. All lines end with CR
, including the last one.
PRO f(n)
DR "MA0,199"
p(n,90)
RET
PRO p(n,a)
I n
n=n-.5
DR "RT",a
p(n,-a)
DR "FD4"
p(n,a)
DR "FD4"
p(n,-a)
DR "LT",a
EN
RET
Expanded and commented
PROCEDURE f(n) ! main procedure, taking the number 'n' of iterations
DRAW "MA0,199" ! move the pen to absolute position (0, 199)
p(n,90) ! initial call to 'p' with 'a' = +90
RETURN ! end of procedure
PROCEDURE p(n,a) ! recursive procedure taking 'n' and the angle 'a'
IF n ! if 'n' is not equal to 0:
n=n-0.5 ! subtract 0.5 from 'n'
DRAW "RT",a ! right turn of 'a' degrees
p(n,-a) ! recursive call with '-a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,a) ! recursive call with 'a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,-a) ! recursive call with '-a'
DRAW "LT",a ! left turn of 'a' degrees
ENDIF ! end
RETURN ! end of procedure
Example output
add a comment |
up vote
12
down vote
up vote
12
down vote
GFA Basic 3.51 (Atari ST), 156 134 124 bytes
A manually edited listing in .LST format. All lines end with CR
, including the last one.
PRO f(n)
DR "MA0,199"
p(n,90)
RET
PRO p(n,a)
I n
n=n-.5
DR "RT",a
p(n,-a)
DR "FD4"
p(n,a)
DR "FD4"
p(n,-a)
DR "LT",a
EN
RET
Expanded and commented
PROCEDURE f(n) ! main procedure, taking the number 'n' of iterations
DRAW "MA0,199" ! move the pen to absolute position (0, 199)
p(n,90) ! initial call to 'p' with 'a' = +90
RETURN ! end of procedure
PROCEDURE p(n,a) ! recursive procedure taking 'n' and the angle 'a'
IF n ! if 'n' is not equal to 0:
n=n-0.5 ! subtract 0.5 from 'n'
DRAW "RT",a ! right turn of 'a' degrees
p(n,-a) ! recursive call with '-a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,a) ! recursive call with 'a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,-a) ! recursive call with '-a'
DRAW "LT",a ! left turn of 'a' degrees
ENDIF ! end
RETURN ! end of procedure
Example output
GFA Basic 3.51 (Atari ST), 156 134 124 bytes
A manually edited listing in .LST format. All lines end with CR
, including the last one.
PRO f(n)
DR "MA0,199"
p(n,90)
RET
PRO p(n,a)
I n
n=n-.5
DR "RT",a
p(n,-a)
DR "FD4"
p(n,a)
DR "FD4"
p(n,-a)
DR "LT",a
EN
RET
Expanded and commented
PROCEDURE f(n) ! main procedure, taking the number 'n' of iterations
DRAW "MA0,199" ! move the pen to absolute position (0, 199)
p(n,90) ! initial call to 'p' with 'a' = +90
RETURN ! end of procedure
PROCEDURE p(n,a) ! recursive procedure taking 'n' and the angle 'a'
IF n ! if 'n' is not equal to 0:
n=n-0.5 ! subtract 0.5 from 'n'
DRAW "RT",a ! right turn of 'a' degrees
p(n,-a) ! recursive call with '-a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,a) ! recursive call with 'a'
DRAW "FD4" ! move the pen 4 pixels forward
p(n,-a) ! recursive call with '-a'
DRAW "LT",a ! left turn of 'a' degrees
ENDIF ! end
RETURN ! end of procedure
Example output
edited Nov 19 at 17:53
answered Nov 18 at 13:55
Arnauld
70.3k686296
70.3k686296
add a comment |
add a comment |
up vote
10
down vote
Perl 6, 117 bytes
{map ->y{|map {(((++$+y)%2+$++)%3**(y+$^v,*/3...*%3)??$^s[$++%2]!!'│')xx$_*3},<┌ ┐>,$_,<└ ┘>,1},^$_}o*R**3
Try it online!
0-indexed. Returns a 2D array of Unicode characters. The basic idea is that for lower rows, the expression
(x + (x+y)%2) % (3 ** trailing_zeros_in_base3(3*(y+1)))
yields the pattern
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|................||........ % 9
..||....||....||....||....| % 3
|....||....||....||....||.. % 3
........||................| % 9
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|.......................... % 27
For upper rows, the expression is
(x + (x+y+1)%2) % (3 ** trailing_zeros_in_base3(3*(y+3**n)))
Explanation
{ ... }o*R**3 # Feed $_ = 3^n into block
map ->y{ ... },^$_ # Map y = 0..3^n-1
|map { ... },<┌ ┐>,$_,<└ ┘>,1 # Map pairs (('┌','┐'),3^n) for upper rows
# and (('└','┘'),1) for lower rows.
# Block takes items as s and v
( ... )xx$_*3 # Evaluate 3^(n+1) times, returning a list
(++$+y)%2 # (x+y+1)%2 for upper rows, (x+y)%2 for lower rows
( +$++) # Add x
(y+$^v,*/3...*%3) # Count trailing zeros of 3*(y+v) in base 3
3** # nth power of 3
% # Modulo
??$^s[$++%2] # If there's a remainder yield chars in s alternately
!!'│' # otherwise yield '│'
add a comment |
up vote
10
down vote
Perl 6, 117 bytes
{map ->y{|map {(((++$+y)%2+$++)%3**(y+$^v,*/3...*%3)??$^s[$++%2]!!'│')xx$_*3},<┌ ┐>,$_,<└ ┘>,1},^$_}o*R**3
Try it online!
0-indexed. Returns a 2D array of Unicode characters. The basic idea is that for lower rows, the expression
(x + (x+y)%2) % (3 ** trailing_zeros_in_base3(3*(y+1)))
yields the pattern
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|................||........ % 9
..||....||....||....||....| % 3
|....||....||....||....||.. % 3
........||................| % 9
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|.......................... % 27
For upper rows, the expression is
(x + (x+y+1)%2) % (3 ** trailing_zeros_in_base3(3*(y+3**n)))
Explanation
{ ... }o*R**3 # Feed $_ = 3^n into block
map ->y{ ... },^$_ # Map y = 0..3^n-1
|map { ... },<┌ ┐>,$_,<└ ┘>,1 # Map pairs (('┌','┐'),3^n) for upper rows
# and (('└','┘'),1) for lower rows.
# Block takes items as s and v
( ... )xx$_*3 # Evaluate 3^(n+1) times, returning a list
(++$+y)%2 # (x+y+1)%2 for upper rows, (x+y)%2 for lower rows
( +$++) # Add x
(y+$^v,*/3...*%3) # Count trailing zeros of 3*(y+v) in base 3
3** # nth power of 3
% # Modulo
??$^s[$++%2] # If there's a remainder yield chars in s alternately
!!'│' # otherwise yield '│'
add a comment |
up vote
10
down vote
up vote
10
down vote
Perl 6, 117 bytes
{map ->y{|map {(((++$+y)%2+$++)%3**(y+$^v,*/3...*%3)??$^s[$++%2]!!'│')xx$_*3},<┌ ┐>,$_,<└ ┘>,1},^$_}o*R**3
Try it online!
0-indexed. Returns a 2D array of Unicode characters. The basic idea is that for lower rows, the expression
(x + (x+y)%2) % (3 ** trailing_zeros_in_base3(3*(y+1)))
yields the pattern
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|................||........ % 9
..||....||....||....||....| % 3
|....||....||....||....||.. % 3
........||................| % 9
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|.......................... % 27
For upper rows, the expression is
(x + (x+y+1)%2) % (3 ** trailing_zeros_in_base3(3*(y+3**n)))
Explanation
{ ... }o*R**3 # Feed $_ = 3^n into block
map ->y{ ... },^$_ # Map y = 0..3^n-1
|map { ... },<┌ ┐>,$_,<└ ┘>,1 # Map pairs (('┌','┐'),3^n) for upper rows
# and (('└','┘'),1) for lower rows.
# Block takes items as s and v
( ... )xx$_*3 # Evaluate 3^(n+1) times, returning a list
(++$+y)%2 # (x+y+1)%2 for upper rows, (x+y)%2 for lower rows
( +$++) # Add x
(y+$^v,*/3...*%3) # Count trailing zeros of 3*(y+v) in base 3
3** # nth power of 3
% # Modulo
??$^s[$++%2] # If there's a remainder yield chars in s alternately
!!'│' # otherwise yield '│'
Perl 6, 117 bytes
{map ->y{|map {(((++$+y)%2+$++)%3**(y+$^v,*/3...*%3)??$^s[$++%2]!!'│')xx$_*3},<┌ ┐>,$_,<└ ┘>,1},^$_}o*R**3
Try it online!
0-indexed. Returns a 2D array of Unicode characters. The basic idea is that for lower rows, the expression
(x + (x+y)%2) % (3 ** trailing_zeros_in_base3(3*(y+1)))
yields the pattern
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|................||........ % 9
..||....||....||....||....| % 3
|....||....||....||....||.. % 3
........||................| % 9
|....||....||....||....||.. % 3
..||....||....||....||....| % 3
|.......................... % 27
For upper rows, the expression is
(x + (x+y+1)%2) % (3 ** trailing_zeros_in_base3(3*(y+3**n)))
Explanation
{ ... }o*R**3 # Feed $_ = 3^n into block
map ->y{ ... },^$_ # Map y = 0..3^n-1
|map { ... },<┌ ┐>,$_,<└ ┘>,1 # Map pairs (('┌','┐'),3^n) for upper rows
# and (('└','┘'),1) for lower rows.
# Block takes items as s and v
( ... )xx$_*3 # Evaluate 3^(n+1) times, returning a list
(++$+y)%2 # (x+y+1)%2 for upper rows, (x+y)%2 for lower rows
( +$++) # Add x
(y+$^v,*/3...*%3) # Count trailing zeros of 3*(y+v) in base 3
3** # nth power of 3
% # Modulo
??$^s[$++%2] # If there's a remainder yield chars in s alternately
!!'│' # otherwise yield '│'
edited Nov 18 at 21:48
answered Nov 18 at 15:06
nwellnhof
6,3231125
6,3231125
add a comment |
add a comment |
up vote
6
down vote
K (ngn/k), 37 27 26 bytes
{+y,(|'y:x,,>*x),x}/1,&2*
Try it online!
returns a boolean matrix
|'y
is syntax specific to ngn/k. other dialects require a :
to make an each-ed verb monadic: |:'y
1
To make the output more beautiful, highlight all occurences of1
(if supported by your browser)
– user202729
Nov 18 at 9:32
3
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
add a comment |
up vote
6
down vote
K (ngn/k), 37 27 26 bytes
{+y,(|'y:x,,>*x),x}/1,&2*
Try it online!
returns a boolean matrix
|'y
is syntax specific to ngn/k. other dialects require a :
to make an each-ed verb monadic: |:'y
1
To make the output more beautiful, highlight all occurences of1
(if supported by your browser)
– user202729
Nov 18 at 9:32
3
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
add a comment |
up vote
6
down vote
up vote
6
down vote
K (ngn/k), 37 27 26 bytes
{+y,(|'y:x,,>*x),x}/1,&2*
Try it online!
returns a boolean matrix
|'y
is syntax specific to ngn/k. other dialects require a :
to make an each-ed verb monadic: |:'y
K (ngn/k), 37 27 26 bytes
{+y,(|'y:x,,>*x),x}/1,&2*
Try it online!
returns a boolean matrix
|'y
is syntax specific to ngn/k. other dialects require a :
to make an each-ed verb monadic: |:'y
edited Nov 18 at 13:21
answered Nov 18 at 9:10
ngn
6,53312459
6,53312459
1
To make the output more beautiful, highlight all occurences of1
(if supported by your browser)
– user202729
Nov 18 at 9:32
3
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
add a comment |
1
To make the output more beautiful, highlight all occurences of1
(if supported by your browser)
– user202729
Nov 18 at 9:32
3
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
1
1
To make the output more beautiful, highlight all occurences of
1
(if supported by your browser)– user202729
Nov 18 at 9:32
To make the output more beautiful, highlight all occurences of
1
(if supported by your browser)– user202729
Nov 18 at 9:32
3
3
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
@user202729 done - in the footer so it don't affect the byte count
– ngn
Nov 18 at 9:55
add a comment |
up vote
5
down vote
Wolfram Language 83 36 bytes, (possibly -48 bytes with bonus)
As of version 11.1, PeanoCurve
is a built-in.
My original, clumsy submission wasted many bytes on GeometricTransformation
and ReflectionTransform.
This much reduced version was suggested by alephalpha.
Reverse
was required to orient the output properly.
Graphics[Reverse/@#&/@PeanoCurve@#]&
Example 36 bytes
Graphics[Reverse/@#&/@PeanoCurve@#]&[3]
Bonus
If this qualifies for the 100 pt bonus, it weighs in at 52 - 100 = -48
The code [5]
was not counted, only the pure function.
Table[Graphics[Reverse/@#&/@PeanoCurve@#]&@k{k,#}&[5]
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
add a comment |
up vote
5
down vote
Wolfram Language 83 36 bytes, (possibly -48 bytes with bonus)
As of version 11.1, PeanoCurve
is a built-in.
My original, clumsy submission wasted many bytes on GeometricTransformation
and ReflectionTransform.
This much reduced version was suggested by alephalpha.
Reverse
was required to orient the output properly.
Graphics[Reverse/@#&/@PeanoCurve@#]&
Example 36 bytes
Graphics[Reverse/@#&/@PeanoCurve@#]&[3]
Bonus
If this qualifies for the 100 pt bonus, it weighs in at 52 - 100 = -48
The code [5]
was not counted, only the pure function.
Table[Graphics[Reverse/@#&/@PeanoCurve@#]&@k{k,#}&[5]
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
add a comment |
up vote
5
down vote
up vote
5
down vote
Wolfram Language 83 36 bytes, (possibly -48 bytes with bonus)
As of version 11.1, PeanoCurve
is a built-in.
My original, clumsy submission wasted many bytes on GeometricTransformation
and ReflectionTransform.
This much reduced version was suggested by alephalpha.
Reverse
was required to orient the output properly.
Graphics[Reverse/@#&/@PeanoCurve@#]&
Example 36 bytes
Graphics[Reverse/@#&/@PeanoCurve@#]&[3]
Bonus
If this qualifies for the 100 pt bonus, it weighs in at 52 - 100 = -48
The code [5]
was not counted, only the pure function.
Table[Graphics[Reverse/@#&/@PeanoCurve@#]&@k{k,#}&[5]
Wolfram Language 83 36 bytes, (possibly -48 bytes with bonus)
As of version 11.1, PeanoCurve
is a built-in.
My original, clumsy submission wasted many bytes on GeometricTransformation
and ReflectionTransform.
This much reduced version was suggested by alephalpha.
Reverse
was required to orient the output properly.
Graphics[Reverse/@#&/@PeanoCurve@#]&
Example 36 bytes
Graphics[Reverse/@#&/@PeanoCurve@#]&[3]
Bonus
If this qualifies for the 100 pt bonus, it weighs in at 52 - 100 = -48
The code [5]
was not counted, only the pure function.
Table[Graphics[Reverse/@#&/@PeanoCurve@#]&@k{k,#}&[5]
edited Nov 19 at 14:27
answered Nov 18 at 3:23
DavidC
23.6k243101
23.6k243101
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
add a comment |
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
Graphics[Reverse/@#&/@PeanoCurve@#]&
– alephalpha
Nov 18 at 12:19
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
It feels a bit like cheating to have a function which calculates the Peano curve by itself, but I'll take it as accepted answer since it's pretty impressive nonetheless ;). @LegionMammal978 I think you deserve to post your own answer, I'd argue that it's different enough to warrant accepting it as winning answer.
– Peiffap
Nov 19 at 10:01
add a comment |
up vote
4
down vote
BBC BASIC, 142 ASCII characters (130 bytes tokenised)
Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html
I.m:q=FNh(m,8,8,0)END
DEFFNh(n,x,y,i)
IFn F.i=0TO8q=FNh(n-1,x-i MOD3MOD2*2*x,y-i DIV3MOD2*2*y,i)DRAWBY(1AND36/2^i)*x,y*(12653/3^i MOD3-1)N.
=0
add a comment |
up vote
4
down vote
BBC BASIC, 142 ASCII characters (130 bytes tokenised)
Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html
I.m:q=FNh(m,8,8,0)END
DEFFNh(n,x,y,i)
IFn F.i=0TO8q=FNh(n-1,x-i MOD3MOD2*2*x,y-i DIV3MOD2*2*y,i)DRAWBY(1AND36/2^i)*x,y*(12653/3^i MOD3-1)N.
=0
add a comment |
up vote
4
down vote
up vote
4
down vote
BBC BASIC, 142 ASCII characters (130 bytes tokenised)
Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html
I.m:q=FNh(m,8,8,0)END
DEFFNh(n,x,y,i)
IFn F.i=0TO8q=FNh(n-1,x-i MOD3MOD2*2*x,y-i DIV3MOD2*2*y,i)DRAWBY(1AND36/2^i)*x,y*(12653/3^i MOD3-1)N.
=0
BBC BASIC, 142 ASCII characters (130 bytes tokenised)
Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html
I.m:q=FNh(m,8,8,0)END
DEFFNh(n,x,y,i)
IFn F.i=0TO8q=FNh(n-1,x-i MOD3MOD2*2*x,y-i DIV3MOD2*2*y,i)DRAWBY(1AND36/2^i)*x,y*(12653/3^i MOD3-1)N.
=0
answered Nov 18 at 13:32
Level River St
20.1k32579
20.1k32579
add a comment |
add a comment |
up vote
4
down vote
HTML+SVG+JS, 224 213 bytes
The output is mirrored horizontally.
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
Try it online! (prints the HTML)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
add a comment |
up vote
4
down vote
HTML+SVG+JS, 224 213 bytes
The output is mirrored horizontally.
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
Try it online! (prints the HTML)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
add a comment |
up vote
4
down vote
up vote
4
down vote
HTML+SVG+JS, 224 213 bytes
The output is mirrored horizontally.
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
Try it online! (prints the HTML)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
HTML+SVG+JS, 224 213 bytes
The output is mirrored horizontally.
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
Try it online! (prints the HTML)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
(
n=>document.write(`<svg width=${w=3**n*9} height=${w}><path d="M1 ${(p=(n,z)=>n--&&(p(n,-z,a(a(p(n,-z,d+=z)),p(n,z))),d-=z))(n*2,r=d=x=y=1,a=_=>r+=`L${x+=~-(d&=3)%2*9} ${y+=(2-d)%2*9}`)&&r}"fill=#fff stroke=red>`)
)(3)
edited Nov 18 at 14:40
answered Nov 18 at 11:08
Arnauld
70.3k686296
70.3k686296
add a comment |
add a comment |
up vote
3
down vote
Logo, 89 bytes
to p:n:a
if:n>0[rt:a
p:n-1 0-:a
fw 5
p:n-1:a
fw 5
p:n-1 0-:a
lt:a]end
to f:n
p:n*2 90
end
Port of @Arnauld's Atari BASIC answer. To use, do something like this:
reset
f 3
add a comment |
up vote
3
down vote
Logo, 89 bytes
to p:n:a
if:n>0[rt:a
p:n-1 0-:a
fw 5
p:n-1:a
fw 5
p:n-1 0-:a
lt:a]end
to f:n
p:n*2 90
end
Port of @Arnauld's Atari BASIC answer. To use, do something like this:
reset
f 3
add a comment |
up vote
3
down vote
up vote
3
down vote
Logo, 89 bytes
to p:n:a
if:n>0[rt:a
p:n-1 0-:a
fw 5
p:n-1:a
fw 5
p:n-1 0-:a
lt:a]end
to f:n
p:n*2 90
end
Port of @Arnauld's Atari BASIC answer. To use, do something like this:
reset
f 3
Logo, 89 bytes
to p:n:a
if:n>0[rt:a
p:n-1 0-:a
fw 5
p:n-1:a
fw 5
p:n-1 0-:a
lt:a]end
to f:n
p:n*2 90
end
Port of @Arnauld's Atari BASIC answer. To use, do something like this:
reset
f 3
answered Nov 18 at 20:33
Neil
78.5k744175
78.5k744175
add a comment |
add a comment |
up vote
2
down vote
Stax, 19 bytes
∩▐j>♣←╙~◘∩╗╢a╘─Ràô
Run and debug it
Output for 3:
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
█ █ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ █ █
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
add a comment |
up vote
2
down vote
Stax, 19 bytes
∩▐j>♣←╙~◘∩╗╢a╘─Ràô
Run and debug it
Output for 3:
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
█ █ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ █ █
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
add a comment |
up vote
2
down vote
up vote
2
down vote
Stax, 19 bytes
∩▐j>♣←╙~◘∩╗╢a╘─Ràô
Run and debug it
Output for 3:
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
█ █ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ █ █
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
Stax, 19 bytes
∩▐j>♣←╙~◘∩╗╢a╘─Ràô
Run and debug it
Output for 3:
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
█ █ █
█ ███ ███ ███ ███ ███ ███ ███ ███ █ █ ███ ███ ███ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ █ █
███ ███ ███ ███ █ █ ███ ███ ███ ███ ███ ███ ███ ███ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
█ █ █ █ █ █ █ █ █
█ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ █ █ █ █ █ █ █ █
███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █ █ ███ ███ █
█ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
answered Nov 19 at 19:33
recursive
4,9941221
4,9941221
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176168%2fdrawing-the-peano-curve%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Welcome 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 code-golf.
– Shaggy
Nov 17 at 23:43
4
Yeah, I don't think the bonuses are a good idea, especially since there at least two animation-capable ASCII-art focused golflangs
– ASCII-only
Nov 18 at 1:46
2
Oh 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
Nov 18 at 2:03
2
Also, what stops anyone from making a trivial spacefilling curve (just zigzagging back and forth) for non-square dimensions
– ASCII-only
Nov 18 at 2:11
7
Bonuses 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
Nov 18 at 5:14