# 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.

• What is the winning criterion ? And is this a challenge or a golf ? Oct 12, 2012 at 15:33
• I read "kolmogorov-complexity" as "code-golf". Oct 12, 2012 at 16:44
• @DavidCarraher "kolmogorov-complexity" was edited in after the question was asked. The original questioner has not specified the winning criteria yet. Oct 12, 2012 at 20:56
• @Gareth My comment was made after the "kolmogorov-complexity" tag was added but before the "code-golf" tag was added. At that time people were still be asking whether it was a code-golf question. Oct 12, 2012 at 22:00
• perlmonks.com/?node_id=891559 has perl solutions. Oct 20, 2012 at 19:51

## Javascript, 10396938988 87

f=(i=[...Array(17)].map((x,i)=>i<8?i:i-2*(i-8)))=>i.map(x=>i.map(y=>x+y>7?(x+y-7):' ').join).join\n


I haven't looked at the other answers up until this point, and just started out with this spreadsheet. Just saw that this answer isn't too bad of a golf compared to the other Javascript answers.

I tried to be clever coming up with something that generates a particular array (i) that I use for the x and y-axis. But it turns out, spelling out that array is shorter.

f=(i=[0,1,2,3,4,5,6,7,8,7,6,5,4,3,2,1,0])=>i.map(x=>i.map(y=>x+y>7?(x+y-7):' ').join).join\n


Update. Spelling out the array differently, but I'm sure that I can golf this further

f=(i=[...'01234567876543210'])=>i.map(x=>i.map(y=>1*x+1*y>7?(1*x+1*y-7):' ').join).join\n


Last update for tonight:

f=(i=[...'01234567876543210'])=>i.map(x=>i.map(y=>+x+1*y>7?+x+1*y-7:' ').join).join\n


Getting rid of one more byte:

f=(i=[...'0'+10*11111111**2])=>i.map(x=>i.map(y=>+x+1*y>7?+x+1*y-7:' ').join).join\n


And one more:

f=(i=[0,...11111111**2+'0'])=>i.map(x=>i.map(y=>+x+1*y>7?+x+1*y-7:' ').join).join\n


# Duocentehexaquinquagesimal, 58 bytes

(Úv×H.F°ǝ=ÉÈNŸ=~ʒ€
₁Ë¨DûlN₆rÇX³ΣJd‘×∞*Åv€rØ(0ÕœÖ¤ΔNā—St€ô


Try it online!

# FreeBASIC, 100 characters

Dim As Byte i,j,k
for i=-8 to 8 : for j=-8 to 9
k=abs(i)+abs(j)
if k > 8 then print " "; : else : ? chr(57-k);
next
?
next
Sleep
End


# Perl 5, 33 bytes

say$"x abs.(1x(9-abs))**2for-8..8  Try it online! Using 11 * 11 = 121, 111 * 111 = 12321, 1111 * 1111 = 1234321, ... 3 bytes saved thanks to naffetS. • 33: say$"x abs.(1x(9-abs))**2for-8..8 Mar 15 at 2:53

# Go, 239 196 187 185 bytes

import(."fmt";."strings")
func g(i int){P:=Print;P(Repeat(" ",(9-i)))
for j:=1;j<=i;j++{P(j)}
for k:=i-1;k>0;k--{P(k)}
P("\n")}
func f(){
for i:=1;i<10;i++{g(i)}
for i:=8;i>0;i--{g(i)}}


Attempt This Online!

My first attempt at golfing in Go. This can definitely be shortened, but I don't know how.

#### Commented

import (."fmt"; ."strings")        // Import modules for later
func g(i int) {                    // Helper function g taking an int i
P := Print                         //  Useful function for later
P(Repeat(" ", (9 - i)))            //  Repeat a space 9-i times and print
for j := 1; j <= i; j++ { P(j) }   //  Print each j for j in [1 .. i]
for k := i-1; k > 0; k-- { P(k) }  //  Print each k for k in [i .. 1]
P("\n") }                          //  Print a newline
func f(){                          // Function boilerplate
for i := 1; i < 10; i++ { g(i) }   //  Call g for each i in [1 .. 9]
for i := 8; i > 0; i-- { g(i) }}   //  Call g for each i in [8 .. 1]


# Java 8 (OpenJDK 8), 157 161 bytes

-4 bytes thanks to @ceilingcat

Tried to use only 1 for instead of 2 for two-dimensional printing, but couldn't beat the best Java answers.

interface M{static void main(String[]b){for(int r,s,a=0;a<289;System.out.print((r<1?s<1?" ":"":r)+(s>7?"\n":"")))r=9-Math.abs(s=a%17-8)-Math.abs(8-a++/17);}}
`

Try it online!