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

10 lines
268 B
Python
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
def sierpinski_carpet(n):
carpet = ["#"]
for i in xrange(n):
carpet = [x + x + x for x in carpet] + \
[x + x.replace("#"," ") + x for x in carpet] + \
[x + x + x for x in carpet]
return "\n".join(carpet)
print sierpinski_carpet(3)