all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
18
Task/Sierpinski-carpet/Python/sierpinski-carpet-1.py
Normal file
18
Task/Sierpinski-carpet/Python/sierpinski-carpet-1.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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
|
||||
9
Task/Sierpinski-carpet/Python/sierpinski-carpet-2.py
Normal file
9
Task/Sierpinski-carpet/Python/sierpinski-carpet-2.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue