Cotton fabric used to be an expensive and scarce product. One dealt with it very economically: remainders or old pieces of clothing weren't thrown away, they were recycled. Old pieces were stitched together to serve as a protection against the cold. For example, soldiers in the Middle Ages wore quilted tunics over their clothing in order to stay warm. The Romans knew a kind of quilted bedding they called culcita. This word was later corrupted to cowlte, of which the word quilt was deducted.

Like so many workmanship and handiwork techniques, one made a virtue a necessity when quilting. Quilting a couple of layers of fabric became more and more decorative and was done by patterns, one more artistic than the other. If the upper layer of the quilt consisted of small, sown together pieces of fabric, it is called a patchwork-quilt. Today, the terms patchwork and quilt are both used to indicate the same thing, since most quilts are constructed from patchwork.

Today, there is an abundance of cheap cotton fabrics and there are affordable warm blankets and one of course no longer depends on remainders or old clothing. Making patchwork hasn't been a necessity for a while now, but it is still done as a hobby.

een patchwork-quilt
A modern patchwork-quilt.

Assignment

Define a class Quilt with which the patterns of a quilt can be represented. Every quilt corresponds with a representation of a number of characters in the format of a grid. For example, a $$2\times 4$$ quilt could look as follows:

//-\
++||

The class must implement the following methods:

Objects of the class Quilt must be immutable. No other method may adjust the internal state of an object from the class Quilt. In other words, the internal state of the objects may not be changed after being initialized, which only allows making new objects.

Example

Remark: if you wish to use the interactive Python session below as a doctest, all backslashes of the output (that have already been escaped once below), must be escaped. In other words, all backslashes in the actual result must be replaced by a double backslash.

>>> quilt = Quilt(2, 2, '//++')
>>> print(quilt)
//
++
>>> quilt += Quilt(2, 2, '-\\||')
>>> print(quilt)
//-\
++||
>>> quilt
Quilt(2, 4, '//-\\++||')
>>> quilt = quilt.rotate()
>>> print(quilt)
+\
+\
-|
-/
>>> quilt
Quilt(4, 2, '+\\+\\-|-/')
>>> quilt += Quilt(2, 2, '-\\||')
Traceback (most recent call last):
AssertionError: quilts do not have an equal height
>>> quilt = quilt.rotate()
>>> print(quilt)
||++
\-//
>>> Quilt(2, 3, '++++')
Traceback (most recent call last):
AssertionError: invalid configuration
>>> Quilt(2, 3, 'oxooXo')
Traceback (most recent call last):
AssertionError: invalid configuration