Problem 5, Part 2

Draw the following pattern:

....1....
...222...
..33333..
.4444444.
555555555
.6666666.
..77777..
...888...
....9....

You are given the size of the image (as height).

Data:

DIGITS_RE

Express a sequence of digits

PATTERN_RE

Express the output line

Functions:

draw(height)

Draw the pattern of size given as height and return the text lines.

DIGITS_RE = re.compile('\\d+')

Express a sequence of digits

PATTERN_RE = re.compile('^(?P<leftpad>[.]*)\\d+(?P<rightpad>[.]*)$')

Express the output line

draw(height: int) Lines[source]

Draw the pattern of size given as height and return the text lines.

Requires
  • height <= 9

  • height % 2 == 1

  • height > 0

Ensures
  • len(result) == height

  • all(len(line) == height for line in result)

  • all(
    (
            mtch := PATTERN_RE.match(line),
            mtch is not None
            and mtch.group('leftpad') == mtch.group('rightpad')
    )[1]
    for line in result)
    
  • (
            middle := int(height / 2),
            DIGITS_RE.fullmatch(result[middle])
    )[1]