Step 01 Beginner Problems — Patterns
Pattern 12 — Number Crown Pattern
Two number triangles facing each other across a closing gap: the left side counts up 1, 2, 3, ... while the right side mirrors it back down, and in the last row the two sides meet to form the palindrome 1 2 3 4 4 3 2 1. It is the classic number crown — a lesson in splitting a row into a left part, a gap, and a right part.
1 1 1 2 2 1 1 2 3 3 2 1 1 2 3 4 4 3 2 1
How to think about it
Use 1-based rows r = 1, 2, ..., n. Row r has three parts: a left run of the numbers 1..r, a middle gap of 2(n - r) empty slots, and a right run of the numbers r..1 in decreasing order. The total slots per row are r + 2(n - r) + r = 2n — constant for every row — which is why all rows have the same printed width. As r grows by 1, each side gains one number and the gap loses two slots, so the sides march toward each other until at r = n the gap vanishes and the row reads 1..n followed by n..1.
Code
The code builds the left list [1..r], a gap list of 2(n - r) single-space placeholders, and the right list [r..1], then joins everything with spaces. Using a blank string as a placeholder token keeps every slot the same width, so the right side stays perfectly aligned as the gap shrinks.
def pattern(n):
for i in range(n):
r = i + 1
left = [str(x) for x in range(1, r + 1)]
gap = [" "] * (2 * (n - r))
right = [str(x) for x in range(r, 0, -1)]
print(" ".join(left + gap + right))Key points
- Row r = left run (1..r) + gap of 2(n - r) slots + right run (r..1).
- Every row occupies exactly 2n slots — constant width is the alignment guarantee.
- Each step down: the sides grow by 1 each and the gap shrinks by 2.
- The final row is a palindrome: 1 2 ... n n ... 2 1.
- Placeholder tokens (' ') keep spacing uniform; printing raw spaces inline is where alignment usually breaks.