frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Sierpiński Triangle? In My Bitwise and?

https://lcamtuf.substack.com/p/sierpinski-triangle-in-my-bitwise
87•guiambros•3h ago

Comments

jcul•3h ago
I can't dismiss the cookie popup on this page. After rejecting or accepting cookies it reloads and reappears.

Apologies for a comment not related to the content, but it makes it difficult to read the article on mobile.

jcul•2h ago
Really interesting, and surprising article though!
IceDane•2h ago
Same problem here. Firefox on Android.
peterburkimsher•2h ago
Wolfram did a lot of research into cellular automata, and the Sierpinski Triangle kept showing up there too:

https://www.wolframscience.com/nks/

GuB-42•2h ago
This one in particular: https://en.wikipedia.org/wiki/Rule_90
jesuslop•2h ago
You get those also doing a Pascal triangle mod 2, so a xor. Is a zoom-out fractal as oposed to Mandelbrot set.
anthk•2h ago
True. pas.f in Forth

    : .r u.r ;
    : position  ( row -- )  cr  33 swap 2 *  - spaces  ;
    : pas ( 0 ... 0 -- 0 ... 0 )    0 >r begin
    over + >r  dup 0= until
    begin  r> dup while  dup 4 .r  repeat  ;
    : pass  ( -- )    0 1 0    18 0 ?do  dup position  >r  pas  r>  1+  loop      drop  ;
    : pax  ( 0 ... 0 -- )  drop begin 0= until ;
    : pascal  ( -- )  pass pax ;

    pascal
    cr
The same mod2:

    : .r u.r ;
    : position  ( row -- )  cr  33 swap 2 *  - spaces  ;
    : pas ( 0 ... 0 -- 0 ... 0 )    0 >r begin
     over + >r  dup 0= until
     begin  r> dup while  dup 2 mod 4 .r  repeat  ;
    : pass  ( -- )    0 1 0    18 0 ?do  dup position  >r  pas  r>  1+  loop     drop  ;
    : pax  ( 0 ... 0 -- )  drop begin 0= until ;
    : pascal  ( -- )  pass pax ;

    pascal
    cr
A Forth for people in a hurry:

     git clone https://github.com/howerj/subleq
     cd subleq
     sed -i 's,0 constant opt.control,1 constant opt.control,g' subleq.fth
     gmake subleq
     ./subleq subleq.dec < subleq.fth > new.dec
     ./subleq new.dec < pas.f
kragen•1h ago
Output from `cr pascal` in GForth:

                                    1
                                  1   1
                                1   0   1
                              1   1   1   1
                            1   0   0   0   1
                          1   1   0   0   1   1
                        1   0   1   0   1   0   1
                      1   1   1   1   1   1   1   1
                    1   0   0   0   0   0   0   0   1
                  1   1   0   0   0   0   0   0   1   1
                1   0   1   0   0   0   0   0   1   0   1
              1   1   1   1   0   0   0   0   1   1   1   1
            1   0   0   0   1   0   0   0   1   0   0   0   1
          1   1   0   0   1   1   0   0   1   1   0   0   1   1
        1   0   1   0   1   0   1   0   1   0   1   0   1   0   1
      1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
    1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1 ok
By changing `4 .r` to `bl + dup dup dup emit emit emit emit` I get this:

                                      !!!!
                                    !!!!!!!!
                                  !!!!    !!!!
                                !!!!!!!!!!!!!!!!
                              !!!!            !!!!
                            !!!!!!!!        !!!!!!!!
                          !!!!    !!!!    !!!!    !!!!
                        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                      !!!!                            !!!!
                    !!!!!!!!                        !!!!!!!!
                  !!!!    !!!!                    !!!!    !!!!
                !!!!!!!!!!!!!!!!                !!!!!!!!!!!!!!!!
              !!!!            !!!!            !!!!            !!!!
            !!!!!!!!        !!!!!!!!        !!!!!!!!        !!!!!!!!
          !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !!!!                                                            !!!!
    !!!!!!!!                                                        !!!!!!!! ok
But this is not using bitwise AND, just the Pascal's triangle approach. (Interestingly, you can reformulate that as a neighborhood-2 2-state 1-dimensional cellular automaton pretty easily; it occurs in a couple of different guises in Wolfram's catalog.)

Here's an ASCII-art version that uses AND as Michał describes:

    32 value size  : line cr size 0 do dup i and if bl else [char] # then dup emit emit loop drop ;
    : pasand size 0 do i line loop ;                                                           
Running `pasand` then yields this:

    ################################################################
    ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  
    ####    ####    ####    ####    ####    ####    ####    ####    
    ##      ##      ##      ##      ##      ##      ##      ##      
    ########        ########        ########        ########        
    ##  ##          ##  ##          ##  ##          ##  ##          
    ####            ####            ####            ####            
    ##              ##              ##              ##              
    ################                ################                
    ##  ##  ##  ##                  ##  ##  ##  ##                  
    ####    ####                    ####    ####                    
    ##      ##                      ##      ##                      
    ########                        ########                        
    ##  ##                          ##  ##                          
    ####                            ####                            
    ##                              ##                              
    ################################                                
    ##  ##  ##  ##  ##  ##  ##  ##                                  
    ####    ####    ####    ####                                    
    ##      ##      ##      ##                                      
    ########        ########                                        
    ##  ##          ##  ##                                          
    ####            ####                                            
    ##              ##                                              
    ################                                                
    ##  ##  ##  ##                                                  
    ####    ####                                                    
    ##      ##                                                      
    ########                                                        
    ##  ##                                                          
    ####                                                            
    ##                                                               ok
anthk•1h ago
Straight from the blog, too, from C to Forth:

   : sier cr 32 0 do 32 0 do i j and if ."   " else ." * " then loop cr loop ;
   sier

Output from eforth/subleq (with do...loop set in the config):

    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
    *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   
    * *     * *     * *     * *     * *     * *     * *     * *     
    *       *       *       *       *       *       *       *       
    * * * *         * * * *         * * * *         * * * *         
    *   *           *   *           *   *           *   *           
    * *             * *             * *             * *             
    *               *               *               *               
    * * * * * * * *                 * * * * * * * *                 
    *   *   *   *                   *   *   *   *                   
    * *     * *                     * *     * *                     
    *       *                       *       *                       
    * * * *                         * * * *                         
    *   *                           *   *                           
    * *                             * *                             
    *                               *                               
    * * * * * * * * * * * * * * * *                                 
    *   *   *   *   *   *   *   *                                   
    * *     * *     * *     * *                                     
    *       *       *       *                                       
    * * * *         * * * *                                         
    *   *           *   *                                           
    * *             * *                                             
    *               *                                               
    * * * * * * * *                                                 
    *   *   *   *                                                   
    * *     * *                                                     
    *       *                                                       
    * * * *                                                         
    *   *                                                           
    * *                                                             
    *                                                               
     ok
     ok
kragen•42m ago
That looks nicer than my version. But you should put the `cr` before the inner loop, not after it. That way you can remove the `cr` before the outer loop.
dvt•2h ago
Just a heads up, all (binary?) logical operators produce fractals. This is pretty well-known[1].

[1] https://icefractal.com/articles/bitwise-fractals/

wang_li•30m ago
The change rate in binary notation is fractal.
zX41ZdbW•2h ago
Sierpinski also sounds nice in music. Examples here: https://github.com/ClickHouse/NoiSQL
gjm11•2h ago
Here's a possibly-too-highbrow explanation to complement the nice simple one in the OP.

"As everyone knows", you get a Sierpinski triangle by taking the entries in Pascal's triangle mod 2. That is, taking binomial coefficients mod 2.

Now, here's a cute theorem about binomial coefficients and prime numbers: for any prime p, the number of powers of p dividing (n choose r) equals the number of carries when you write r and n-r in base p and add them up.

For instance, (16 choose 8) is a multiple of 9 but not of 27. 8 in base 3 is 22; when you add 22+22 in base 3, you have carries out of the units and threes digits.

OK. So, now, suppose you look at (x+y choose x) mod 2. This will be 1 exactly when no 2s divide it; i.e., when no carries occur when adding x and y in binary; i.e., when x and y never have 1-bits in the same place; i.e., when x AND y (bitwise) is zero.

And that's exactly what OP found!

tomrod•2h ago
I prefer mine au naturale 3-adic.

https://m.youtube.com/watch?v=tRaq4aYPzCc

Just kidding. This was a fun read.

kragen•1h ago
The 31-byte demo "Klappquadrat" by T$ is based on this phenomenon; I wrote a page about how it works a few years ago, including a working Python2 reimplementation with Numpy: http://canonical.org/~kragen/demo/klappquadrat.html

I should probably update that page to explain how to use objdump correctly to disassemble MS-DOG .COM files.

If you like making fractal patterns with bitwise arithmetic, you'll probably love http://canonical.org/~kragen/sw/dev3/trama. Especially if you like stack machines too. The page is entirely in Spanish (except for an epilepsy safety warning) but I suspect that's unlikely to be a problem in practice.

userbinator•45m ago
Sierpinski triangles are definitely a common sight in demoscene productions, to the point that they're acceptable in the smaller sizes, but others will think you're not good enough if that's all you do for a 64k or above entry.
marvinborner•1h ago
Very cool! This basically encodes a quad-tree of bits where every except one quadrant of each subquadrant recurses on the parent quad-tree.

The corresponding equivalent of functional programming would be Church bits in a functional quad-tree encoding \s.(s TL TR BL BR). Then, the Sierpinski triangle can be written as (Y \fs.(s f f f #f)), where #f is the Church bit \tf.f!

Rendering proof: https://lambda-screen.marvinborner.de/?term=ERoc0CrbYIA%3D

zabzonk•1h ago
I draw these with paper and pen when I am extremely bored in meetings.
susam•1h ago
I’d like to share some little demos here.

Bitwise XOR modulo T: https://susam.net/fxyt.html#XYxTN1srN255pTN1sqD

Bitwise AND modulo T: https://susam.net/fxyt.html#XYaTN1srN255pTN1sqN0

Bitwise OR modulo T: https://susam.net/fxyt.html#XYoTN1srN255pTN1sqDN0S

Where T is the time coordinate. Origin for X, Y coordinates is at the bottom left corner of the canvas.

You can pause the animation anytime by clicking the ‘■’ button and then step through the T coordinate using the ‘«’ and ‘»’ buttons.

kragen•40m ago
Gorgeous!
anyfoo•27m ago
Ah. Is that while LFSR (linear feedback shift registers) and specifically PRBS (pseudo-random binary sequences) produce Sierpinski triangles as well?

PRBS sequences are well-known, well-used "pseudo-random" sequences that are, for example, used for (non-cryptographically!) scramble data links, or to just test them (Bit Error Rate).

I made my own PRBS generator, and was surprised that visualizing its output, it was full of Sierpinski triangles of various sizes.

Even fully knowing and honoring that they have no cryptographic properties, it didn't feel very "pseudo-random" to me.

modeless•13m ago
Try this one liner pasted into a Unix shell:

  cc -w -xc -std=c89 -<<<'main(c){int r;for(r=32;r;)printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}'&&./a.*
It used to be cooler back when compilers supported weird K&R style C by default. I got it under 100 characters back then, and the C part was just 73 characters. This version is a bit longer but works with modern clang.
Terr_•8m ago
Instructions unclear, machine rooted. :p

GeoHack [MediaWiki tool for collecting/organizing geospatial data]

https://geohack.toolforge.org/
1•nativeit•3m ago•1 comments

What happens when a hegemon falls?

https://www.economist.com/finance-and-economics/2025/05/08/what-happens-when-a-hegemon-falls
1•Swizec•4m ago•0 comments

Copyright and Artificial Intelligence Part 3: Generative AI Training [pdf]

https://copyright.gov/ai/Copyright-and-Artificial-Intelligence-Part-3-Generative-AI-Training-Report-Pre-Publication-Version.pdf
1•Kye•5m ago•0 comments

Claude's System Prompt: Chatbots Are More Than Just Models

https://www.dbreunig.com/2025/05/07/claude-s-system-prompt-chatbots-are-more-than-just-models.html
1•misonic•7m ago•0 comments

My Month of Living Quince's Low-Cost Life of Luxury

https://www.nytimes.com/wirecutter/reviews/my-month-testing-quince-products/
1•xqcgrek2•12m ago•0 comments

Swift for WebAssembly [video]

https://www.youtube.com/watch?v=cJyNok8OAuE
1•TheWiggles•12m ago•0 comments

Is the Southern accent fixin' to disappear in parts of the US South?

https://apnews.com/article/migration-southern-accent-georgia-louisiana-north-carolina-1f8bfc59f869ccccaed6a87cdaa83ee8
1•pseudolus•15m ago•0 comments

EU abandons ePrivacy reform to boost AI competitiveness

https://techcrunch.com/2025/02/12/eu-abandons-eprivacy-reform-as-bloc-shifts-focus-to-competitiveness-and-fostering-data-access-for-ai/
3•bit_qntum•19m ago•0 comments

Senators probe Google–Anthropic, Microsoft–OpenAI deals over antitrust concerns

https://www.computerworld.com/article/3958091/senators-probe-google-anthropic-microsoft-openai-deals-over-antitrust-concerns.html
4•byte-bolter•19m ago•0 comments

Scoring the European Citizen in the AI Era

https://arxiv.org/abs/2505.02791
3•gray_amps•22m ago•0 comments

Rubicon: Precise Microarchitectural Attacks with Page-Granular Massaging

https://comsec.ethz.ch/research/dram/rubicon/
1•pabs3•23m ago•0 comments

The Little Kindgom (1982)

https://www.folklore.org/The_Little_Kingdom.html
1•kristianp•24m ago•0 comments

Ireland given two months to implement hate speech laws or face action from EU

https://www.thejournal.ie/ireland-given-two-months-to-start-implementing-hate-speech-laws-6697853-May2025/
1•like_any_other•25m ago•0 comments

This is Water by David Foster Wallace

https://fs.blog/david-foster-wallace-this-is-water/
1•alihm•28m ago•0 comments

Show HN: CXcompress v1.0.0-beta: fast lossless pre-procecssing text compressor

https://github.com/seccode/CXcompress
1•s3cfast•30m ago•0 comments

Wikipedia: Lamest Edit Wars

https://en.wikipedia.org/wiki/Wikipedia:Lamest_edit_wars
1•jsheard•32m ago•1 comments

Coding a Web Server in 25 Lines (2024) [video]

https://www.youtube.com/watch?v=7GBlCinu9yg
1•indigodaddy•33m ago•0 comments

Where does the ginseng in your tea come from? Graphic memoir explains the trade

https://www.npr.org/2025/05/09/nx-s1-5137011/ginseng-roots-craig-thompson-blankets
1•srameshc•39m ago•0 comments

Top 5 New Artificial Intelligence Innovations in 2025

https://wilnickmagazine.com/5-new-artificial-intelligence-in-2025/
1•Wilnick•43m ago•0 comments

Show HN: Swytch – A lightweight, alternative web framework in C#

https://github.com/Gwali-1/Swytch
1•Gwali-Gwali•47m ago•0 comments

Elizabeth Holmes's Partner Has a New Blood-Testing Startup

https://www.nytimes.com/2025/05/10/business/elizabeth-holmes-partner-blood-testing-startup.html
1•lxm•48m ago•0 comments

Police, researchers disrupt botnet comprising EOL residential routers

https://www.bleepingcomputer.com/news/security/police-dismantles-botnet-selling-hacked-routers-as-residential-proxies/
2•heresie-dabord•54m ago•0 comments

Denoro, a CLI tool to explore Deno KV local databases

https://davrodpin.github.io/denoro/
1•davrodpin•57m ago•1 comments

UK plans to end 'failed free market experiment' in immigration

https://www.reuters.com/world/uk/uk-plans-end-failed-free-market-experiment-immigration-2025-05-10/
2•thunderbong•59m ago•0 comments

Made In China 2025

https://en.wikipedia.org/wiki/Made_in_China_2025
4•kaycebasques•1h ago•0 comments

Scraipe: AI Scraping and Analysis Framework

https://github.com/SnpM/scraipe
1•snpm•1h ago•1 comments

Ask HN: What do you actually do with your wearable health data?

1•dzohrob•1h ago•0 comments

Zero ships from China are bound for California's top ports

https://www.cnn.com/2025/05/10/business/zero-ships-china-trade-ports-pandemic
10•Anon84•1h ago•0 comments

Craigslist revenue drops to 300M, one-third of 2018 total

https://www.jobboardhive.com/2025/04/03/craigslist-revenue-traffic-drops-again-one-third-of-2018-total/
2•walterbell•1h ago•1 comments

No One Was Talking

https://space.tcsenpai.com/no-one-was-talking-emergent-discourse-between-autonomous-language-models-in-a-reflexive-test-of-meaning-ethics-and-error/
1•erdaniels•1h ago•1 comments