Skip to content

Instantly share code, notes, and snippets.

@CodeGolfScotland
Last active February 24, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeGolfScotland/4f026b4a458e69aa9995333912f5bc5b to your computer and use it in GitHub Desktop.
Save CodeGolfScotland/4f026b4a458e69aa9995333912f5bc5b to your computer and use it in GitHub Desktop.
Code Golf February 2017

February 2017 - Print a Diamond Matrix

Task

Print a Diamond Matrix x numbers deep, x will always be greater than 0 and less than 10.

Examples:

(4) => 
        1
       121
      12321
     1234321
      12321
       121
        1

(9) => 
        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321
 123456787654321
  1234567654321
   12345654321
    123454321
     1234321
      12321
       121
        1

(1) => 1

*^You can assume that you will always recieved valid input

About Code Golf Scotland

Copy link

ghost commented Feb 24, 2017

Language: JS
Length: 88
Solution:

x=n=>{for(i=n;--i+n;console.log(s))for(j=n;j;s=j--^n?k>0?k+s+k:" "+s:k+"")k=i<0?j+i:j-i}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment