1 Replies - 2646 Views - Last Post: 02 June 2012 - 08:25 PM

#1 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Sierpinski carpet

Posted 09 April 2009 - 10:36 AM

Description:
def inside(a,b):
    stop=False
    while not stop:
        if a==0 or b==0:
            return True
        elif a%3==1 and b%3==1:
            return stop
 
        a=a/3
        b=b/3
 

def carpet(n):
    for i in range(pow(3,n)):
        for j in range(pow(3,n)):
            if inside(i,j):
                print "*",
            else:
                print " ",
        print " "


Is This A Good Question/Topic? 0
  • +

Replies To: Sierpinski carpet

#2 dave_6_10   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 19-March 08

Re: Sierpinski carpet

Posted 02 June 2012 - 08:25 PM

That's a fun snippet. I only had to add parenthesis on the three print prompts to make it work for py3 and by changing the astrik to various line designs it created nice carpets :) thank you for sharing
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1