B←{'/\ '['\/'⍳⍺⍺⍵]} C←⊢,⌽B C(⊢⍪⊖B)⊃,/{C⊖A↑⊖' /'[⍵≤∘.+⍨⍳⍵+1]}¨⌽⍳A←⎕
Try it online!
Assumes ⎕IO←0, which is standard on many systems, so the program is 0-indexed.
This is a tradfn that takes input via STDIN.
Explanation
(slightly outdated)
Note that ⍺ is the left argument, ⍵ is the right argument and ⍺⍺ is the left operator.
B is a function that helps in mirroring the diamonds. It takes the string as the right argument and the reverse function as the left (so B is an operator).
B←{'/\ '['\/'⍳⍺⍺⍵]} ⍺⍺⍵ Apply ⍺⍺ on ⍵ '\/'⍳ Find the index of the reflected string in '\/' (if the character is not found in `'\/'`, then return an index out of the bounds of the string, ie `2` if the character is a space) '/\ '[ ] Use these indexes on '/\ ' to reflect the '/\' characters
And now we go to the main part of the program.
A←⎕ Assign the input to variable A ⍳ Create a range 0 .. A-1 ⌽ Reverse it so that it becomes A-1 .. 0 ¨ For each element do (the right argument is the element): ⍳⍵+1 Create a range 0 .. ⍵ ∘.+⍨ Create an addition table using the range to result in a matrix like so: 0+0 0+1 0+2 .. 0+⍵ 1+0 1+1 1+2 .. 1+⍵ 2+0 2+1 2+2 .. 2+⍵ ... ⍵+0 ⍵+1 ⍵+2 .. ⍵+⍵ ⍵≤ The elements of the matrix that are greater than or equal to the ⍵, this creates a triangle matrix that looks like this: 0 0 .. 0 1 0 0 .. 1 1 .. 1 1 .. 1 1 ' /'[...] Index it in ' /' to get a character matrix (ie replace 0s with spaces and 1s with '/'s) ⊖ Flip this vertically A↑ Pad the top spaces
This is necessary to ensure that all the triangles created for every element in the range ⌽⍳A have the same height so that they can be later concatenated with each other.
⊖ Flip the matrix vertically again to go back to the original state (⊢, ) Concatenate it with ⌽B itself, but flipped horizontally ,/ Concatenate all triangles formed by the range operator ⊃ The resulting matrix is nested, so this operator "un-nests" it
Now the top left part of the pattern is complete. All that's remaining is to flip it vertically and then horizontally.
(⊢⍪⊖B) Concatenate the resulting matrix with itself but flipped vertically (the vertically flipped matrix is concatenated below of the original matrix) Now the left part of the pattern is complete (⊢,⌽B) Concatenate the resulting matrix with itself flipped horizontally
And that's it! The output is a character matrix with /\s and padded with spaces.