First of all ... I would like to wish everyone a Merry Christmas (sorry if I am a day late for your timezone).

To celebrate the occasion, we are going to draw a snowflake. Because the year is 2015 and Christmas is on the 25th (for a large portion of persons), we will draw a Pentaflake. The Pentaflake is a simple fractal composed of pentagons. Here are a few examples (taken from here):enter image description here

Each Pentaflake has an order n. The Pentaflake of order 0 is simply a pentagon. For all other orders n, a Pentaflake is composed of 5 Pentaflakes of the previous order arranged around a 6th Pentaflake of the previous order. For example, a Pentaflake of order 1 is composed of 5 pentagons arranged around a central pentagon.


The order n. This may be given in any way except that of a predefined variable.


An image of the order n Pentaflake. Must be at least 100px wide and 100px long. It may be saved to a file, displayed to the user, or outputted to STDOUT. Any other form of output is not allowed. All image formats existing before this challenge are allowed.


As codegolf, the person with the least number of bytes wins.

  • 3
    \$\begingroup\$ -1 because snowflakes only have 6 fold symmetry! =D \$\endgroup\$
    – flawr
    Commented Dec 25, 2015 at 16:30
  • 1
    \$\begingroup\$ @flawr According to this article only about .1% of snowflakes actually have 6-fold symmetry ... or any symmetry at all. However, those snowflakes that do have symmetry can have 3-fold symmetry in addition to 6-fold symmetry :P \$\endgroup\$ Commented Dec 26, 2015 at 14:27
  • 5
    \$\begingroup\$ Well this article only studied way less than .1% of all snowflakes, and it is meaningless anyway, as they only studied american snowflakes. I bet metric snowflakes are way more symmetrical! (PS: Beautiful images! Snowflake #167 is especially interesting!) (I just noticed that metric snowflakes must have 10-fold symmetry.) \$\endgroup\$
    – flawr
    Commented Dec 26, 2015 at 14:30
  • 1
    \$\begingroup\$ It will be okay as long as it outputs using one of the above methods. However, n cannot be predefined in your script file. You can read n from STDIN, prompt it from the user, take it as a function / commad line argument ... basically anything you want except for directly embedding it in your code. \$\endgroup\$ Commented Dec 27, 2015 at 0:20
  • 4
    \$\begingroup\$ Don't want to +1 this because it has 25 :( \$\endgroup\$ Commented Jan 6, 2016 at 3:23

7 Answers 7


Matlab, 226

function P(M);function c(L,X,Y,O);hold on;F=.5+5^.5/2;a=2*pi*(1:5)/5;b=a(1)/2;C=F^(2*L);x=cos(a+O*b)/C;y=sin(a+O*b)/C;if L<M;c(L+1,X,Y,~O);for k=1:5;c(L+1,X+x(k),Y+y(k),O);end;else;fill(X+x*F, Y+y*F,'k');end;end;c(0,0,0,0);end


function P(M);                
function c(L,X,Y,O);          %recursive function
hold on;
F=.5+5^.5/2;                  %golden ratio
a=2*pi*(1:5)/5;               %full circle divided in 5 parts (angles)
x=cos(a+O*b)/C;               %calculate the relative position ofnext iteration
if L<M;                       %current recursion (L) < Maximum (M)? recurse
    c(L+1,X,Y,~O);            %call recursion for inner pentagon
    for k=1:5;
        c(L+1,X+x(k),Y+y(k),O)%call recursion for the outer pentagons
else;                         %draw
    fill(X+x*F, Y+y*F,'k');  

Fifth iteration (already took quite a while to render).

enter image description here

A slight alteration of the code (unfortunately more bytes) results in this beauty=)

enter image description here

Oh, and another one:

enter image description here

  • \$\begingroup\$ Thanks for pointing me to this challenge, I went and added another solution, hope you don't mind;) I'm safely away from your byte-count, anyway, I just found it too interesting to miss. \$\endgroup\$ Commented Dec 26, 2015 at 19:26

Mathematica, 200 bytes


The last line is a function which can be applied to an integer n.

Mathematica function names are long. Somebody should entropy-encode them and make a new language from it. :)

When applied to 1:

enter image description here

When applied to 2:

enter image description here


MATLAB, 235 233 217 bytes

Update: a bunch of suggestions from @flawr helped me lose 16 bytes. Since only this allowed me to beat flawr's solution, and that I wouldn't have found the challenge without flawr's help in the first place, consider this a joint submission by us:)

N=input('');f=2*pi/5;c=1.5+5^.5/2;g=0:f:6;p=[cos(g);sin(g)];R=[p(:,2),[-p(2,2);p(1,2)]];for n=1:N,t=p;q=[];for l=0:4,q=[q R^l*[c-1+t(1,:);t(2,:)]/c];end,p=[q -t/c];end,p=reshape(p',5,[],2);fill(p(:,:,1),p(:,:,2),'k');

This is another MATLAB solution, this one based on a philosophy of iterated function systems. I was mostly interested in developing the algorithm itself, and I haven't golfed too much on the solution. There's surely room for improvement. (I contemplated using a hard-coded fixed-point approximation for c, but that wouldn't be nice.)

Ungolfed version:

N=input('');                                % read order from stdin

f=2*pi/5;                                   % angle of 5-fold rotation
c=1.5+5^.5/2;                               % scaling factor for contraction

p=[cos(g);sin(g)];                          % starting pentagon, outer radius 1
R=[p(:,2),[-p(2,2);p(1,2)]];                % 2d rotation matrix with angle f

for n=1:N,                                  % iterate the points
    for l=0:4,
       q=[q R^l*[c-1+t(1,:);t(2,:)]/c];     % add contracted-rotated points
    p=[q -t/c];                             % add contracted middle block

p=reshape(p',5,[],2);                 % reshape to 5x[]x2 matrix to separate pentagons
fill(p(:,:,1),p(:,:,2),'k');          % plot pentagons

Result for N=5 (with a subsequent axis equal off for prettiness, but I hope that doesn't count byte-wise):

N=5 pentaflake

  • 1
    \$\begingroup\$ I think you could save a few bytes by using R=[p(:,2),[-p(2,2);p(1,2)]]; (and eliminating the previous R,C,S) and you can use q=[q R^l*[c-1+t(1,:);t(2,:)]/c] and I think c=1.5+5^.5/2; \$\endgroup\$
    – flawr
    Commented Jan 1, 2016 at 11:13
  • \$\begingroup\$ @flawr obviously you're right:) 1. thanks for the rotation matrix, 2. thanks for the new q, I even had a needless pair of parentheses in there... 3. thanks, but what is this magic??:D 4. since the solution is now shorter than your original, I consider this to be partly your submission as well. \$\endgroup\$ Commented Jan 3, 2016 at 21:45

Mathematica, 124 bytes

Mathematica supports new syntax for Table since version 10: Table[expr, n], which saves another byte. Table[expr, n] is equivalent to Table[expr, {n}].


The core of this function is using complex numbers to do tranformations and then convert them to points by ReIm.

Test case:


enter image description here

  • 1
    \$\begingroup\$ π takes up two bytes in UTF-8, so you come out to 125 bytes total. \$\endgroup\$ Commented Jan 4, 2016 at 4:58
  • \$\begingroup\$ OMFG what is this \$\endgroup\$ Commented Jan 5, 2016 at 22:04

Mathematica, 199 196 bytes

Edging out Peter Richter's answer by a hair, here's one of my own. It leans heavily on graphics functionality, and less on math and FP. The CirclePoints builtin is new in 10.1.


Edit: Thanks to DumpsterDoofus for GoldenRatio

  • \$\begingroup\$ You can save 3 bytes by replacing ((1+Sqrt@5)/2) with GoldenRatio. Also in the second line I think it should be p@0=Polygon@c[{1,0},5]; instead of p@0=Polygon@cp[{1,0},5];. (BTW I'm actually Peter, I've got two profiles lol). \$\endgroup\$ Commented Dec 27, 2015 at 3:42
  • \$\begingroup\$ Yes! Good call. I spotted the typo, too, but forgot to fix it. D'oh, \$\endgroup\$ Commented Dec 27, 2015 at 3:43

Mathematica, 130 bytes

r=Exp[Pi.4I Range@5]

I use a similar technique to njpipeorgan's answer (in fact I stole his 2Pi I/5 == Pi.4I trick), but implemented as a recursive function.

Example usage (using % to access the anonymous function that was output on the last line):


enter image description here


Wolfram Language (Mathematica), 96 90 84bytes


enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.