View Single Post
Old 05-02-2007, 23:11   #11
marco.r
Senior Member
 
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
Ti scrivo il codice in python che forse di da l'idea di come funziona.
Codice:
from sys import stdout


def step(n,table,xbase,ybase):
    if n == 1:
        table[(xbase,ybase)] = True
    else:
        # alto sinistra
        step(n/2,table,xbase,ybase)
        # basso sinistra
        step(n/2,table,xbase,ybase+n/2)
        # basso destra
        step(n/2,table,xbase+n/2,ybase+n/2)
        

def sierpinsky(n):
    table = {}
    step(n,table,0,0)
    for y in range(n):
        for x in range(n):
            if (x,y) in table:
                stdout.write('x')
            else:
                stdout.write(' ')
        stdout.write('\n')
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele
marco.r è offline   Rispondi citando il messaggio o parte di esso