I imagine this problem as two triangles overlapping each other. You can write two functions that checks whether a coordinate is in a triangle. For example, this code
for i in range(n):
for j in range(n):
if left(i,j):
print '*',
else:
print '.',
print
gives this output:
* . . . . . .
* * . . . . .
* * * . . . .
* * * * . . .
* * * * * . .
* * * * * * .
* * * * * * *
Changing left
to right
gives the mirror image:
. . . . . . *
. . . . . * *
. . . . * * *
. . . * * * *
. . * * * * *
. * * * * * *
* * * * * * *
Once you've figured out the correct implementation of left
and right
, just combine the two as left(i,j) or right(i,j)
to get the M
shape:
* . . . . . *
* * . . . * *
* * * . * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…