Skip to main content
deleted 2 characters in body
Source Link
marinus
  • 31.2k
  • 7
  • 71
  • 112

APL (5251)

      A←67⍴0⋄A[34]←1⋄' ○'[1+32 67⍴{~⊃⍵:⍵,∇~(1⌽⍵)=¯1⌽⍵⋄⍬≠¯1⌽⍵⋄⍬}A]
  • A←67⍴0: A is a vector of 67 zeroes
  • A[34]←1: the 34th element is 1
  • {...}A: starting with A, do:
  • ~⊃⍵:: if the first element of the current row is zero
  • ⍵,∇: add the current row to the answer, and recurse with:
  • ~(1⌽⍵)=¯1⌽⍵≠¯1⌽⍵: the vector where each element is the XOR of its neighbours in the previous generation
  • ⋄⍬: otherwise, we're done
  • 32 67⍴: format this in a 67x32 matrix
  • 1+: add one to select the right value from the character array
  • ' ○'[...]: output either a space (not part of the triangle) or a circle (when it is part of the triangle)

APL (52)

      A←67⍴0⋄A[34]←1⋄' ○'[1+32 67⍴{~⊃⍵:⍵,∇~(1⌽⍵)=¯1⌽⍵⋄⍬}A]
  • A←67⍴0: A is a vector of 67 zeroes
  • A[34]←1: the 34th element is 1
  • {...}A: starting with A, do:
  • ~⊃⍵:: if the first element of the current row is zero
  • ⍵,∇: add the current row to the answer, and recurse with:
  • ~(1⌽⍵)=¯1⌽⍵: the vector where each element is the XOR of its neighbours in the previous generation
  • ⋄⍬: otherwise, we're done
  • 32 67⍴: format this in a 67x32 matrix
  • 1+: add one to select the right value from the character array
  • ' ○'[...]: output either a space (not part of the triangle) or a circle (when it is part of the triangle)

APL (51)

      A←67⍴0⋄A[34]←1⋄' ○'[1+32 67⍴{~⊃⍵:⍵,(1⌽⍵)≠¯1⌽⍵⋄⍬}A]
  • A←67⍴0: A is a vector of 67 zeroes
  • A[34]←1: the 34th element is 1
  • {...}A: starting with A, do:
  • ~⊃⍵:: if the first element of the current row is zero
  • ⍵,∇: add the current row to the answer, and recurse with:
  • (1⌽⍵)≠¯1⌽⍵: the vector where each element is the XOR of its neighbours in the previous generation
  • ⋄⍬: otherwise, we're done
  • 32 67⍴: format this in a 67x32 matrix
  • 1+: add one to select the right value from the character array
  • ' ○'[...]: output either a space (not part of the triangle) or a circle (when it is part of the triangle)
Source Link
marinus
  • 31.2k
  • 7
  • 71
  • 112

APL (52)

      A←67⍴0⋄A[34]←1⋄' ○'[1+32 67⍴{~⊃⍵:⍵,∇~(1⌽⍵)=¯1⌽⍵⋄⍬}A]

Explanation:

  • A←67⍴0: A is a vector of 67 zeroes
  • A[34]←1: the 34th element is 1
  • {...}A: starting with A, do:
  • ~⊃⍵:: if the first element of the current row is zero
  • ⍵,∇: add the current row to the answer, and recurse with:
  • ~(1⌽⍵)=¯1⌽⍵: the vector where each element is the XOR of its neighbours in the previous generation
  • ⋄⍬: otherwise, we're done
  • 32 67⍴: format this in a 67x32 matrix
  • 1+: add one to select the right value from the character array
  • ' ○'[...]: output either a space (not part of the triangle) or a circle (when it is part of the triangle)

Output:

                                 ○                                 
                                ○ ○                                
                               ○   ○                               
                              ○ ○ ○ ○                              
                             ○       ○                             
                            ○ ○     ○ ○                            
                           ○   ○   ○   ○                           
                          ○ ○ ○ ○ ○ ○ ○ ○                          
                         ○               ○                         
                        ○ ○             ○ ○                        
                       ○   ○           ○   ○                       
                      ○ ○ ○ ○         ○ ○ ○ ○                      
                     ○       ○       ○       ○                     
                    ○ ○     ○ ○     ○ ○     ○ ○                    
                   ○   ○   ○   ○   ○   ○   ○   ○                   
                  ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○                  
                 ○                               ○                 
                ○ ○                             ○ ○                
               ○   ○                           ○   ○               
              ○ ○ ○ ○                         ○ ○ ○ ○              
             ○       ○                       ○       ○             
            ○ ○     ○ ○                     ○ ○     ○ ○            
           ○   ○   ○   ○                   ○   ○   ○   ○           
          ○ ○ ○ ○ ○ ○ ○ ○                 ○ ○ ○ ○ ○ ○ ○ ○          
         ○               ○               ○               ○         
        ○ ○             ○ ○             ○ ○             ○ ○        
       ○   ○           ○   ○           ○   ○           ○   ○       
      ○ ○ ○ ○         ○ ○ ○ ○         ○ ○ ○ ○         ○ ○ ○ ○      
     ○       ○       ○       ○       ○       ○       ○       ○     
    ○ ○     ○ ○     ○ ○     ○ ○     ○ ○     ○ ○     ○ ○     ○ ○    
   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   ○   
  ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○