Problem 2

Draw the following pattern:

  \/
 \\//
\\\///
///\\\
 //\\
  /\

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

Data:

TRAILING_SPACE_RE

Express the trailing whitespace at the end of line

Functions:

draw(width)

Draw the pattern with size given as width and return the text lines.

TRAILING_SPACE_RE = re.compile('\\s$')

Express the trailing whitespace at the end of line

draw(width: int) Lines[source]

Draw the pattern with size given as width and return the text lines.

Requires
  • width % 2 == 0

  • width > 0

Ensures
  • all(len(line) > 0 for line in result)

  • len(result) > 0

  • len(result) % 2 == 0

  • all(not TRAILING_SPACE_RE.match(line) for line in result)

  • all(
        len(line.strip()) % 2 == 0
        for line in result
    )
    
  • all(
        line.strip().startswith('/') and line.endswith('\\')
        for line in result[int(len(result) / 2):]
    )
    
  • all(
        line.strip().startswith('\\') and line.endswith('/')
        for line in result[:int(len(result) / 2)]
    )