[ prog / sol / mona ]

prog


The Forced Indentation Of Code

171 2022-08-19 10:10

Sierpinski triangle >>21 >>153 >>157 in m4 >>161:

$ cat triangle.m4 
divert(-1)
define(`triangle_level',5)
define(`triangle_empty',` ')
define(`triangle_left',`◢')
define(`triangle_right',`◣')
define(`triangle_size',eval(2**triangle_level))
define(`triangle_cell',`ifelse(eval($2>$1),1,0,`ifelse($1,0,$3,`ifelse(eval($1<$4),1,`triangle_cell($1,$2,$3,eval($4/2))',`ifelse(eval($2<$4),1,`triangle_cell(eval($1-$4),eval($4-1-$2),eval(-($3)),eval($4/2))',`triangle_cell(eval($1-$4),eval($2-$4),$3,eval($4/2))')')')')')
define(`triangle_char',`ifelse($1,-1,triangle_left,$1,1,triangle_right,triangle_empty)')
define(`triangle_symbol',`ifelse(eval($2<triangle_size),1,`triangle_char(triangle_cell($1,eval(triangle_size-1-$2),-1,eval(triangle_size/2)))',`triangle_char(triangle_cell($1,eval($2-triangle_size),1,eval(triangle_size/2)))')')
define(`triangle_xjoin',`ifelse($1,1,`$2(0)`$4'',`triangle_xjoin(decr($1),`$2',`$3',`$3'$2(decr($1))`$4')')')
define(`triangle_linesymbol',`triangle_symbol(triangle_currentline,$1)')
define(`triangle_line',`pushdef(`triangle_currentline',$1)triangle_xjoin(eval(2*triangle_size),`triangle_linesymbol',,)popdef(`triangle_currentline')')
define(`triangle_triangle',`triangle_xjoin(triangle_size,`triangle_line',`
',)')
divert(0)triangle_triangle
$ m4 triangle.m4 
                               ◢◣                               
                              ◢◣◢◣                              
                             ◢◣  ◢◣                             
                            ◢◣◢◣◢◣◢◣                            
                           ◢◣      ◢◣                           
                          ◢◣◢◣    ◢◣◢◣                          
                         ◢◣  ◢◣  ◢◣  ◢◣                         
                        ◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣                        
                       ◢◣              ◢◣                       
                      ◢◣◢◣            ◢◣◢◣                      
                     ◢◣  ◢◣          ◢◣  ◢◣                     
                    ◢◣◢◣◢◣◢◣        ◢◣◢◣◢◣◢◣                    
                   ◢◣      ◢◣      ◢◣      ◢◣                   
                  ◢◣◢◣    ◢◣◢◣    ◢◣◢◣    ◢◣◢◣                  
                 ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣                 
                ◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣                
               ◢◣                              ◢◣               
              ◢◣◢◣                            ◢◣◢◣              
             ◢◣  ◢◣                          ◢◣  ◢◣             
            ◢◣◢◣◢◣◢◣                        ◢◣◢◣◢◣◢◣            
           ◢◣      ◢◣                      ◢◣      ◢◣           
          ◢◣◢◣    ◢◣◢◣                    ◢◣◢◣    ◢◣◢◣          
         ◢◣  ◢◣  ◢◣  ◢◣                  ◢◣  ◢◣  ◢◣  ◢◣         
        ◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣                ◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣        
       ◢◣              ◢◣              ◢◣              ◢◣       
      ◢◣◢◣            ◢◣◢◣            ◢◣◢◣            ◢◣◢◣      
     ◢◣  ◢◣          ◢◣  ◢◣          ◢◣  ◢◣          ◢◣  ◢◣     
    ◢◣◢◣◢◣◢◣        ◢◣◢◣◢◣◢◣        ◢◣◢◣◢◣◢◣        ◢◣◢◣◢◣◢◣    
   ◢◣      ◢◣      ◢◣      ◢◣      ◢◣      ◢◣      ◢◣      ◢◣   
  ◢◣◢◣    ◢◣◢◣    ◢◣◢◣    ◢◣◢◣    ◢◣◢◣    ◢◣◢◣    ◢◣◢◣    ◢◣◢◣  
 ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣  ◢◣ 
◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣◢◣
267


VIP:

do not edit these