language-agnosticcode-golfrosetta-stone

Code Golf: Diamond Pattern


The challenge

The shortest code by character count to output a a pattern of diamonds according to the input.

The input is composed of 3 positive numbers representing the size of the diamond and the size of the grid.

A diamond is made from the ASCII characters / and \ with spaces. A diamond of size 1 is:

/\
\/

The size of the grid consists from width and height of number of diamonds.

Test cases

Input:
    1 6 2
Output:
    /\/\/\/\/\/\
    \/\/\/\/\/\/
    /\/\/\/\/\/\
    \/\/\/\/\/\/

Input: 
    2 2 2
Output:
     /\  /\ 
    /  \/  \
    \  /\  /
     \/  \/ 
     /\  /\ 
    /  \/  \
    \  /\  /
     \/  \/ 

Input 
    4 3 1
Output:
       /\      /\      /\   
      /  \    /  \    /  \
     /    \  /    \  /    \
    /      \/      \/      \
    \      /\      /\      /
     \    /  \    /  \    /
      \  /    \  /    \  /
       \/      \/      \/

Code count includes input/output (i.e full program).


Solution

  • Golfscript - 50 chars

    ~@:3,[{[.3-~' '*\' '*'/'\.'\\'4$]2$*}%n*.-1%]*n*\;