Skip to main content
prettified the longer version
Source Link
walpen
  • 3.4k
  • 2
  • 21
  • 17
j,d[99][99];main(i){d[0][48]=1;ford[0][31]=3;for(;i<98;;i<64;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);j++<50&&main;++j<32&&main(puts(""));}
j,d[99][99]; // these init as 0
main(i){ //starts at 1 (argc)
  d[0][48]=1;d[0][48]=3; //seed the automata (3 gives us # instead of !)
  for(;i<98;) // print a row
    d[j+1][i]=putchar(32|d[j][i+2]]^d[j][i++]);
    //relies on undefined behavoir. Works on ubuntu with gcc ix864
    //does the automata rule. 32 + (bitwise or can serve as + if you know
    //that (a|b)==(a^b)), putchar returns the char it prints
  j++<50&&main++j<32&&main(puts(""));
  // recurse onto the next row if we've done less thanrepeat 5032 rowstimes
  // puts("") prints a newline and returns 1, which is nice
}
                                              ! !       
                                             !   !                                                 
                                            ! ! ! !                                                
                                           !       !                                               
                                          ! !     ! !                                              
                                         !   !   !   !                                             
                                        ! ! ! ! ! ! ! !                                            
                                       !               !                                           
                                      ! !             ! !                                          
                                     !   !           !   !                                         
                                    ! ! ! !         ! ! ! !                                        
                                   !       !       !       !                                       
                                  ! !     ! !     ! !     ! !                                      
                                 !   !   !   !   !   !   !   !                                     
                                ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !                                    
                               !                               !                                   
                              ! !                             ! !                                  
                             !   !                           !   !                                 
                            ! ! ! !                         ! ! ! !                                
                           !       !                       !       !                               
                          ! !     ! !                     ! !     ! !                              
                         !   !   !   !                   !   !   !   !                             
                        ! ! ! ! ! ! ! !                 ! ! ! ! ! ! ! !                            
                       !               !               !               !                           
                      ! !             ! !             ! !             ! !                          
                     !   !           !   !           !   !           !   !                         
                    ! ! ! !         ! ! ! !         ! ! ! !         ! ! ! !                        
                   !       !       !       !       !       !       !       !                       
                  ! !     ! !     ! !     ! !     ! !     ! !     ! !     ! !                      
                 !   !   !   !   !   !   !   !   !   !   !   !   !   !   !   !                     
                ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !                    
               !                                                               !                   
              ! !                                                             ! !                  
             !   !                                                           !   !                 
            ! ! ! !                                                         ! ! ! !                
           !       !                                                       !       !               
          ! !     ! !                                                     ! !     ! !              
         !   !   !   !                                                   !   !   !   !             
        ! ! ! ! ! ! ! !                                                 ! ! ! ! ! ! ! !            
       !               !                                               !               !           
      ! !             ! !                                             ! !             ! !          
     !   !           !   !                                           !   !           !   !         
    ! ! ! !         ! ! ! !                                         ! ! ! !         ! ! ! !        
   !       !       !       !                                       !       !       !       !       
  ! !     ! !     ! !     ! !                                     ! !     ! !     ! !     ! !      
 !   !   !   !   !   !   !   !                                   !   !   !   !   !   !   !   !     
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !                                 ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !    
                               !                               !                               !   
                              ! !                             ! !                             ! !  
                             !   !                           !   !                           !   ! 
                             # #                               
                            #   #                              
                           # # # #                             
                          #       #                            
                         # #     # #                           
                        #   #   #   #                          
                       # # # # # # # #                         
                      #               #                        
                     # #             # #                       
                    #   #           #   #                      
                   # # # #         # # # #                     
                  #       #       #       #                    
                 # #     # #     # #     # #                   
                #   #   #   #   #   #   #   #                  
               # # # # # # # # # # # # # # # #                 
              #                               #                
             # #                             # #               
            #   #                           #   #              
           # # # #                         # # # #             
          #       #                       #       #            
         # #     # #                     # #     # #           
        #   #   #   #                   #   #   #   #          
       # # # # # # # #                 # # # # # # # #         
      #               #               #               #        
     # #             # #             # #             # #       
    #   #           #   #           #   #           #   #      
   # # # #         # # # #         # # # #         # # # #     
  #       #       #       #       #       #       #       #    
 # #     # #     # #     # #     # #     # #     # #     # #   
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #  
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
j,d[99][99];main(i){d[0][48]=1;for(;i<98;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);j++<50&&main(puts(""));}
j,d[99][99]; // these init as 0
main(i){ //starts at 1 (argc)
  d[0][48]=1; //seed the automata
  for(;i<98;) // print a row
    d[j+1][i]=putchar(32|d[j][i+2]]^d[j][i++]);
    //relies on undefined behavoir. Works on ubuntu with gcc ix864
    //does the automata rule. 32 + (bitwise or can serve as + if you know
    //that (a|b)==(a^b)), putchar returns the char it prints
  j++<50&&main(puts(""));
  // recurse onto the next row if we've done less than 50 rows
  // puts("") prints a newline and returns 1, which is nice
}
                                              ! !       
                                             !   !                                                 
                                            ! ! ! !                                                
                                           !       !                                               
                                          ! !     ! !                                              
                                         !   !   !   !                                             
                                        ! ! ! ! ! ! ! !                                            
                                       !               !                                           
                                      ! !             ! !                                          
                                     !   !           !   !                                         
                                    ! ! ! !         ! ! ! !                                        
                                   !       !       !       !                                       
                                  ! !     ! !     ! !     ! !                                      
                                 !   !   !   !   !   !   !   !                                     
                                ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !                                    
                               !                               !                                   
                              ! !                             ! !                                  
                             !   !                           !   !                                 
                            ! ! ! !                         ! ! ! !                                
                           !       !                       !       !                               
                          ! !     ! !                     ! !     ! !                              
                         !   !   !   !                   !   !   !   !                             
                        ! ! ! ! ! ! ! !                 ! ! ! ! ! ! ! !                            
                       !               !               !               !                           
                      ! !             ! !             ! !             ! !                          
                     !   !           !   !           !   !           !   !                         
                    ! ! ! !         ! ! ! !         ! ! ! !         ! ! ! !                        
                   !       !       !       !       !       !       !       !                       
                  ! !     ! !     ! !     ! !     ! !     ! !     ! !     ! !                      
                 !   !   !   !   !   !   !   !   !   !   !   !   !   !   !   !                     
                ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !                    
               !                                                               !                   
              ! !                                                             ! !                  
             !   !                                                           !   !                 
            ! ! ! !                                                         ! ! ! !                
           !       !                                                       !       !               
          ! !     ! !                                                     ! !     ! !              
         !   !   !   !                                                   !   !   !   !             
        ! ! ! ! ! ! ! !                                                 ! ! ! ! ! ! ! !            
       !               !                                               !               !           
      ! !             ! !                                             ! !             ! !          
     !   !           !   !                                           !   !           !   !         
    ! ! ! !         ! ! ! !                                         ! ! ! !         ! ! ! !        
   !       !       !       !                                       !       !       !       !       
  ! !     ! !     ! !     ! !                                     ! !     ! !     ! !     ! !      
 !   !   !   !   !   !   !   !                                   !   !   !   !   !   !   !   !     
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !                                 ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !    
                               !                               !                               !   
                              ! !                             ! !                             ! !  
                             !   !                           !   !                           !   ! 
j,d[99][99];main(i){d[0][31]=3;for(;i<64;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);++j<32&&main(puts(""));}
j,d[99][99]; // these init as 0
main(i){ //starts at 1 (argc)
  d[0][48]=3; //seed the automata (3 gives us # instead of !)
  for(;i<98;) // print a row
    d[j+1][i]=putchar(32|d[j][i+2]]^d[j][i++]);
    //relies on undefined behavoir. Works on ubuntu with gcc ix864
    //does the automata rule. 32 + (bitwise or can serve as + if you know
    //that (a|b)==(a^b)), putchar returns the char it prints
  ++j<32&&main(puts(""));
  // repeat 32 times
  // puts("") prints a newline and returns 1, which is nice
}
                             # #                               
                            #   #                              
                           # # # #                             
                          #       #                            
                         # #     # #                           
                        #   #   #   #                          
                       # # # # # # # #                         
                      #               #                        
                     # #             # #                       
                    #   #           #   #                      
                   # # # #         # # # #                     
                  #       #       #       #                    
                 # #     # #     # #     # #                   
                #   #   #   #   #   #   #   #                  
               # # # # # # # # # # # # # # # #                 
              #                               #                
             # #                             # #               
            #   #                           #   #              
           # # # #                         # # # #             
          #       #                       #       #            
         # #     # #                     # #     # #           
        #   #   #   #                   #   #   #   #          
       # # # # # # # #                 # # # # # # # #         
      #               #               #               #        
     # #             # #             # #             # #       
    #   #           #   #           #   #           #   #      
   # # # #         # # # #         # # # #         # # # #     
  #       #       #       #       #       #       #       #    
 # #     # #     # #     # #     # #     # #     # #     # #   
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #  
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Shortened even more
Source Link
walpen
  • 3.4k
  • 2
  • 21
  • 17

C 127 119 116 108108 65

This isn't as pretty asone uses the Q-Basic answer, but it shows another waytrick of calculating the Sierpinski triangle, using cellular automata. You probably want '#' insteadHTML answer of '!' making up^ i & j getting it to print pretty output would take 1 more char (you can get really ugly output by sacrificing the triangle, but exclamation points cost two fewer charactersa^).

a=32,j;main(i){for(;++i<a;)putchar(a^i&j);++j<a&&main(puts(""));}

To make it pretty turn (32^i&j) to (32|!(i&j)) and turn it from ++i<a to ++i<=a. However wasting chars on looks seems ungolfish to me.

Ugly output:

 ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
""  ""  ""  ""  ""  ""  ""  ""
"# !"# !"# !"# !"# !"# !"# !"#
  $$$$    $$$$    $$$$    $$$$
 !$%$% ! !$%$% ! !$%$% ! !$%$%
""$$&&  ""$$&&  ""$$&&  ""$$&&
"#$%&' !"#$%&' !"#$%&' !"#$%&'
      ((((((((        ((((((((
 ! ! !()()()() ! ! ! !()()()()
""  ""((**((**  ""  ""((**((**
"# !"#()*+()*+ !"# !"#()*+()*+
  $$$$((((,,,,    $$$$((((,,,,
 !$%$%()(),-,- ! !$%$%()(),-,-
""$$&&((**,,..  ""$$&&((**,,..
"#$%&'()*+,-./ !"#$%&'()*+,-./
              0000000000000000
 ! ! ! ! ! ! !0101010101010101
""  ""  ""  ""0022002200220022
"# !"# !"# !"#0123012301230123
  $$$$    $$$$0000444400004444
 !$%$% ! !$%$%0101454501014545
""$$&&  ""$$&&0022446600224466
"#$%&' !"#$%&'0123456701234567
      ((((((((0000000088888888
 ! ! !()()()()0101010189898989
""  ""((**((**0022002288::88::
"# !"#()*+()*+0123012389:;89:;
  $$$$((((,,,,000044448888<<<<
 !$%$%()(),-,-010145458989<=<=
""$$&&((**,,..0022446688::<<>>
"#$%&'()*+,-./0123456789:;<=>?

I actually kind of like how it looks. But if you insist on it being pretty you can dock four chars. Pretty Output:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
  !!  !!  !!  !!  !!  !!  !!  !
  !   !   !   !   !   !   !   !
!!    !!!!    !!!!    !!!!    !
!     ! !     ! !     ! !     !
      !!      !!      !!      !
      !       !       !       !
!!!!!!        !!!!!!!!        !
! ! !         ! ! ! !         !
  !!          !!  !!          !
  !           !   !           !
!!            !!!!            !
!             ! !             !
              !!              !
              !               !
!!!!!!!!!!!!!!                !
! ! ! ! ! ! !                 !
  !!  !!  !!                  !
  !   !   !                   !
!!    !!!!                    !
!     ! !                     !
      !!                      !
      !                       !
!!!!!!                        !
! ! !                         !
  !!                          !
  !                           !
!!                            !
!                             !
                              !
                              !

Leaving up the older 108 char, cellular automata version.

j,d[99][99];main(i){d[0][48]=1;for(;i<98;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);j++<50&&main(puts(""));}

So I don't think I'm going to get it much shorter than this soSo I don't think I'm going to get it much shorter than this so I'll explain the code. I'll explainleave this explanation up, as some of the codetricks could be useful.

C 127 119 116 108

This isn't as pretty as the Q-Basic answer, but it shows another way of calculating the Sierpinski triangle, using cellular automata. You probably want '#' instead of '!' making up the triangle, but exclamation points cost two fewer characters.

j,d[99][99];main(i){d[0][48]=1;for(;i<98;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);j++<50&&main(puts(""));}

So I don't think I'm going to get it much shorter than this so I'll explain the code.

C 127 119 116 108 65

This one uses the trick of the HTML answer of ^ i & j getting it to print pretty output would take 1 more char (you can get really ugly output by sacrificing the a^).

a=32,j;main(i){for(;++i<a;)putchar(a^i&j);++j<a&&main(puts(""));}

To make it pretty turn (32^i&j) to (32|!(i&j)) and turn it from ++i<a to ++i<=a. However wasting chars on looks seems ungolfish to me.

Ugly output:

 ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
""  ""  ""  ""  ""  ""  ""  ""
"# !"# !"# !"# !"# !"# !"# !"#
  $$$$    $$$$    $$$$    $$$$
 !$%$% ! !$%$% ! !$%$% ! !$%$%
""$$&&  ""$$&&  ""$$&&  ""$$&&
"#$%&' !"#$%&' !"#$%&' !"#$%&'
      ((((((((        ((((((((
 ! ! !()()()() ! ! ! !()()()()
""  ""((**((**  ""  ""((**((**
"# !"#()*+()*+ !"# !"#()*+()*+
  $$$$((((,,,,    $$$$((((,,,,
 !$%$%()(),-,- ! !$%$%()(),-,-
""$$&&((**,,..  ""$$&&((**,,..
"#$%&'()*+,-./ !"#$%&'()*+,-./
              0000000000000000
 ! ! ! ! ! ! !0101010101010101
""  ""  ""  ""0022002200220022
"# !"# !"# !"#0123012301230123
  $$$$    $$$$0000444400004444
 !$%$% ! !$%$%0101454501014545
""$$&&  ""$$&&0022446600224466
"#$%&' !"#$%&'0123456701234567
      ((((((((0000000088888888
 ! ! !()()()()0101010189898989
""  ""((**((**0022002288::88::
"# !"#()*+()*+0123012389:;89:;
  $$$$((((,,,,000044448888<<<<
 !$%$%()(),-,-010145458989<=<=
""$$&&((**,,..0022446688::<<>>
"#$%&'()*+,-./0123456789:;<=>?

I actually kind of like how it looks. But if you insist on it being pretty you can dock four chars. Pretty Output:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
  !!  !!  !!  !!  !!  !!  !!  !
  !   !   !   !   !   !   !   !
!!    !!!!    !!!!    !!!!    !
!     ! !     ! !     ! !     !
      !!      !!      !!      !
      !       !       !       !
!!!!!!        !!!!!!!!        !
! ! !         ! ! ! !         !
  !!          !!  !!          !
  !           !   !           !
!!            !!!!            !
!             ! !             !
              !!              !
              !               !
!!!!!!!!!!!!!!                !
! ! ! ! ! ! !                 !
  !!  !!  !!                  !
  !   !   !                   !
!!    !!!!                    !
!     ! !                     !
      !!                      !
      !                       !
!!!!!!                        !
! ! !                         !
  !!                          !
  !                           !
!!                            !
!                             !
                              !
                              !

Leaving up the older 108 char, cellular automata version.

j,d[99][99];main(i){d[0][48]=1;for(;i<98;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);j++<50&&main(puts(""));}

So I don't think I'm going to get it much shorter than this so I'll explain the code. I'll leave this explanation up, as some of the tricks could be useful.

shortened code and explained
Source Link
walpen
  • 3.4k
  • 2
  • 21
  • 17

C 127 119 116116 108

j,d[99][99];main(i){d[0][48]=1;for(i;i<99;i++;i<98;)d[j+1][i]=putchar(32+32|d[j][i+2]^d[j][i++]);j++<50&&main(d[j][i-1]^d[j][i+1]puts("")%2);j++<50&&main;}

So I don't think I'm going to get it much shorter than this so I'll explain the code.

j,d[99][99]; // these init as 0
main(i){ //starts at 1 (argc)
  d[0][48]=1; //seed the automata
  for(;i<98;) // print a row
    d[j+1][i]=putchar(32|d[j][i+2]]^d[j][i++]);
    //relies on undefined behavoir. Works on ubuntu with gcc ix864
    //does the automata rule. 32 + (bitwise or can serve as + if you know
    //that (a|b)==(a^b)), putchar returns the char it prints
  j++<50&&main(puts(""));
  // recurse onto the next row if we've done less than 50 rows
  // puts("") prints a newline and returns 1, which is nice
}

C 127 119 116

j,d[99][99];main(i){d[0][48]=1;for(i;i<99;i++)d[j+1][i]=putchar(32+(d[j][i-1]^d[j][i+1])%2);j++<50&&main(puts(""));}

C 127 119 116 108

j,d[99][99];main(i){d[0][48]=1;for(;i<98;)d[j+1][i]=putchar(32|d[j][i+2]^d[j][i++]);j++<50&&main(puts(""));}

So I don't think I'm going to get it much shorter than this so I'll explain the code.

j,d[99][99]; // these init as 0
main(i){ //starts at 1 (argc)
  d[0][48]=1; //seed the automata
  for(;i<98;) // print a row
    d[j+1][i]=putchar(32|d[j][i+2]]^d[j][i++]);
    //relies on undefined behavoir. Works on ubuntu with gcc ix864
    //does the automata rule. 32 + (bitwise or can serve as + if you know
    //that (a|b)==(a^b)), putchar returns the char it prints
  j++<50&&main(puts(""));
  // recurse onto the next row if we've done less than 50 rows
  // puts("") prints a newline and returns 1, which is nice
}
shortened a bit more
Source Link
walpen
  • 3.4k
  • 2
  • 21
  • 17
Loading
fixed the algorithm
Source Link
walpen
  • 3.4k
  • 2
  • 21
  • 17
Loading
Source Link
walpen
  • 3.4k
  • 2
  • 21
  • 17
Loading