RosettaCodeData/Task/Sierpinski-carpet/Python/sierpinski-carpet-1.py

19 lines
382 B
Python
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
def in_carpet(x, y):
while True:
if x == 0 or y == 0:
return True
elif x % 3 == 1 and y % 3 == 1:
return False
x /= 3
y /= 3
def carpet(n):
for i in xrange(3 ** n):
for j in xrange(3 ** n):
if in_carpet(i, j):
print '*',
else:
print ' ',
print