Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Hollow Diamond by tokiojapan55
def hollow_diamond(side: int, length: int, cw: bool) -> str:
def chars(n, cw):
arround = (side - 1) * 4
i = (arround - n if cw else n) % arround
return chr(ord('a') + i) if i < length else '*'
result = ""
for n in range((side - 1) * 2 + 1):
sp = abs(side - n - 1)
result += ' ' * sp + chars(n, cw)
sp = (side - sp) * 2 - 3
if sp > 0:
result += ' ' * sp + chars(n, not cw)
result += "\n"
return result[:-1]
May 11, 2023
Comments: