joriszwart.nl

I code dreams™

Sierpinski fractal in 28 bytes

100% assembly 80x86 Assembly Code Golf Fractal Math Mode13h MS-DOS™ Old stuff Size coding

Some ages ago there was a competition on #nlcoders doing the Sierpiński triangle in as less bytes as possible.

Of course I was beaten very bad. A 13 byte version using rule 90 exists.

Sierpinski 28 bytes running in DOSBox
Sierpinski 28 bytes running in DOSBox
; 28 byte Sierpinski-fractal  Joris Zwart (C) 1998

            .model tiny
            .code
            org 100h

start:
            mov al,13h
x:
            cwd
y:
            test cl,dl
            jne skip
            int 10h

            mov ah,0ch
skip:
            inc dl
            jns y
            inc cl
            jns x

            cbw
            int 16h

            mov ax,3
            int 10h
            ret

            end start
Poem for Wacław Sierpiński

This assembles down to these 28 bytes:

b0 13 99 84 ca 75 04
cd 10 b4 0c fe c2 79
f4 fe c1 79 ef 98 cd
16 b8 03 00 cd 10 c3

Pseudocode

For the assembly-impaired here is the pseudocode:

FOR X = 0 TO 127
    FOR Y = 0 TO 127
        IF X AND Y THEN PLOT X, Y
    NEXT Y
NEXT X
Pseudo-code Sierpinski using bitwise AND.
Name Size Last Modified
SIERPIN.ASM 259 bytes 12/23/2017 12:23:00 AM
SIERPIN.COM 28 bytes 3/25/2011 9:37:00 PM
sierpinski-logo.png 581 bytes 11/29/2019 9:10:00 PM
sierpinski-logo.svg 1405 bytes 12/24/2021 4:16:00 PM
sierpinski-dosbox.png 13704 bytes 12/6/2015 7:19:00 PM