funcdiamond(centerint)(string,error){if(center&1)==0{return"",errors.New("center row must be an odd number")}returnstrings.Join(makeDiamond(center),"\n"),nil}funcdiamondOfDiamonds(centerint)(string,error){if(center&1)==0{return"",errors.New("center row must be an odd number")}dmd:=makeDiamond(center)outBuf:=make([]string,center)row:=strings.Repeat(" ",center)fori:=0;i<=center/2;i++{rowBuf:=make([]string,center)forj:=rangerowBuf{rowBuf[j]=strings.Repeat(row,center/2-i)+strings.Repeat(dmd[j],2*i+1)+strings.Repeat(row,center/2-i)}outBuf[i],outBuf[center-i-1]=strings.Join(rowBuf,"\n"),strings.Join(rowBuf,"\n")}returnstrings.Join(outBuf,"\n"),nil}funcmakeDiamond(centerint)[]string{outBuf:=make([]string,center)row:=bytes.Repeat([]byte{' '},center)forl,r:=(center/2),(center/2);l>=0;l,r=l-1,r+1{row[l],row[r]='*','*'outBuf[center/2-l],outBuf[center/2+l]=string(row),string(row)}returnoutBuf}
Go (with bonus diamond of diamonds) playground link
Woah that's cool! I wanted to see what your diamond of diamonds looked like!
Thought I'd paste in the medium sized one, and let people go to the playground for the big one!