Skip to main content
1 of 3
Greg Martin
  • 16.2k
  • 4
  • 21
  • 72

Mathematica, 119 bytes

(±n_:=If[n<4,1,±(n-2)+±(n-3)];Graphics@Line[{Re@#,Im@#}&/@Accumulate@Flatten@{0,z=I^(2/3),±# z^(#+{2,4,1})&~Array~#}])&

Unnamed function taking a positive integer argument (1-indexed) and returning graphics output. Example output for the input 16:

enter image description here

Developed simulataneously with flawr's Matlab answer but with many similarities in design—even including the definition I^(2/3) for the sixth root of unity! Easier-to-read version:

1  (±n_:=If[n<4,1,±(n-2)+±(n-3)];
2   Graphics@Line[{Re@#,Im@#}&/@
3   Accumulate@Flatten@
4   {0,z=I^(2/3),±# z^(#+{2,4,1})&~Array~#}
5  ])&

Line 1 defines the Padovan sequence ±n = P(n). Line 4 creates a nested array of complex numbers, defining z along the way; the last part ±# z^(#+{2,4,1})&~Array~# generates many triples, each of which corresponds to the vectors we need to draw to complete the corresponding triangle (the ±# controls the length while the z^(#+{2,4,1}) controls the directions). Line 3 gets rid of the list nesting and then calculates running totals of the complex numbers, to convert from vectors to pure coordinates; line 2 then converts complex numbers to ordered pairs of real numbers, and outputs the corresponding polygonal line.

Greg Martin
  • 16.2k
  • 4
  • 21
  • 72