B←{'/\ '['\/'⍳⍺⍺⍵]}
C←⊢,⌽B
C(⊢⍪⊖B)⊃,/{C⊖A↑⊖' /'[⍵≤∘.+⍨⍳⍵+1]}¨⌽⍳A←⎕
इसे ऑनलाइन आज़माएं!
मान लिया जाता है ⎕IO←0, जो कई प्रणालियों पर मानक है, इसलिए कार्यक्रम 0-अनुक्रमित है।
यह एक ट्रेडफ़न है जो STDIN के माध्यम से इनपुट लेता है।
व्याख्या
(थोड़ा पुराना)
ध्यान दें कि ⍺बाएं तर्क ⍵है, सही तर्क है और ⍺⍺बाएं ऑपरेटर है।
Bएक ऐसा कार्य है जो हीरों को चमकाने में मदद करता है। यह स्ट्रिंग को दाएं तर्क के रूप में और रिवर्स फ़ंक्शन को बाएं के रूप में लेता है (इसलिए Bएक ऑपरेटर है)।
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
और अब हम कार्यक्रम के मुख्य भाग में जाते हैं।
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
यह सुनिश्चित करने के लिए आवश्यक है कि रेंज में प्रत्येक तत्व के लिए बनाए गए सभी त्रिकोणों की ⌽⍳Aऊंचाई समान है ताकि उन्हें बाद में एक-दूसरे के साथ मिलाया जा सके।
⊖ 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
अब पैटर्न का ऊपरी भाग पूरा हो गया है। जो कुछ शेष है, उसे लंबवत और फिर क्षैतिज रूप से फ्लिप करना है।
(⊢⍪⊖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
और बस! आउटपुट /\एस के साथ एक चरित्र मैट्रिक्स है और रिक्त स्थान के साथ गद्देदार है।