String · Pattern
Letter Diamond
Letter Diamond
StringSymbol pattern, solid style, size 5. Changing the rubric, style or size above re-shapes the loops — the structure stays identical while only the printed value or the cell filter changes.
Letter Diamond · output
Symbol · Solid · size 5
n = int(input("Enter number of rows: "))
# Upper half — pyramid grows to its widest row
for i in range(1, n + 1):
w = 2 * i - 1
print((n - i) * " ", end='')
for j in range(1, 2 * i - 1 + 1):
print('*', end='')
print()
# Lower half — pyramid shrinks back to a tip
for i in range(n - 1, 1 - 1, -1):
w = 2 * i - 1
print((n - i) * " ", end='')
for j in range(1, 2 * i - 1 + 1):
print('*', end='')
print()Behind the Scenes Execution
registers · line tracking · call stack · memory regions| Address | Variable | Value |
|---|---|---|
| Stack (4) | ||
| 0x200 | n | 5 |
| 0x204 | i | -1 |
| 0x208 | j | -1 |
| 0x20C | count | 0 |
| String Pool (static) (2) | ||
| 0x400000 | pool["*"] | * |
| 0x400008 | pool["\n"] | \n |
| Heap (9) | ||
| 0x3000 | grid[0] | |
| 0x3020 | grid[1] | |
| 0x3040 | grid[2] | |
| 0x3060 | grid[3] | |
| 0x3080 | grid[4] | |
| 0x30A0 | grid[5] | |
| 0x30C0 | grid[6] | |
| 0x30E0 | grid[7] | |
| 0x3100 | grid[8] | |
Letter Diamond
The grand mirror diamond: A at the tips, ABCDE…DECBA in the middle. It combines two ideas you already know — the diamond width via abs(i - (n-1)) and the row-mirror value via min().
Why this variant exists: Why a Letter Diamond when Diamond already exists? The numeric Diamond carries the row counter as its value (every cell in a row prints the same number), so it teaches shape + padding. The Letter Diamond instead mirrors the values inside each row — A, then ABC, then ABCDE — so it teaches the entirely separate idea of a row-local value rule. Shape and data are independent, and this variant shows why: same outline, different payload.
The size-5 grid
Nine rows in the 9-column frame: the upper half widens to ABCDE DCBA, then the lower half mirrors it back to A. Each row uses margin abs(r - 4) and width 2(4 - abs(r - 4)) + 1, so shape and letters shrink in step.
Off-by-one traps
Computing the margin and the width from different distance values breaks the alignment at the middle row; both must use m = abs(r - 4), and the middle row must be printed once.
Step by step
- Type n when the program asks.
- Section “// Upper half”: loop i = 1 to n, width w = 2*i - 1, with n - i spaces.
- Print min(j, w - j + 1) — the letters mirror around each row’s centre.
- Newline.
- Section “// Lower half”: loop i = n - 1 down to 1 — the same mirrored rule as the rows close back to a tip.
Complexity
When to use it
- Combining two symmetries
- Interview eye-catcher shapes
grid[r] rows in the Heap region and the i / j / count registers on the Stack — every printed character is one write to the grid.Recommended resourcesAffiliate links · may earn us a commission