Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
next(*) solution solution in Clear category for The Hollow Diamond by veky
import string, itertools
def hollow_diamond(side: int, length: int, cw: bool) -> str:
matrix = [[' '] * 2 * side for _ in range(2 * side - 1)]
letters = itertools.islice(string.ascii_lowercase, length)
i, j, t = 0, side - 1, (-1) ** cw
for di, dj in (1, -t), (1, t), (-1, t), (-1, -t):
for _ in range(side - 1):
matrix[i][j], i, j = next(letters, '*'), i + di, j + dj
return '\n'.join(''.join(row).rstrip() for row in matrix)
May 20, 2023
Comments: