Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Print this diamond

This question has been spreading like a virus in my office. There are quite a variety of approaches:

Print the following:

        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321
 123456787654321
  1234567654321
   12345654321
    123454321
     1234321
      12321
       121
        1

Answers are scored in characters with fewer characters being better.

Answer*

Cancel
6
  • 1
    \$\begingroup\$ David, you beat me this time! :-) \$\endgroup\$ Commented Oct 21, 2012 at 15:29
  • 1
    \$\begingroup\$ Another try (55 chars): f = Table[# - Abs@k, {k, -8, 8}] &; f[f[9]] /. n_ /; n < 1 -> "" // Grid \$\endgroup\$ Commented Mar 22, 2013 at 17:56
  • \$\begingroup\$ Still another (71 chars): Table[9 - ManhattanDistance[{9, 10}, {j, k}], {j, 18}, {k, 18}] /. n_ /; n < 1 -> "" // Grid \$\endgroup\$ Commented Mar 22, 2013 at 17:57
  • 2
    \$\begingroup\$ Grid@#@#@9&[Table[#-Abs@k,{k,-8,8}]&]/.n_/;n<1->"" 50 chars. \$\endgroup\$ Commented Mar 23, 2013 at 4:26
  • \$\begingroup\$ A visual display of the code: ArrayPlot[Sum[k~DiamondMatrix~17, {k, 0, 8}], AspectRatio -> 2] \$\endgroup\$ Commented Nov 23, 2013 at 15:53