实现一个Frieze程序，能根据文本内容显示不同的图案。

## General presentation

You will design and implement a program that will

- check whether some numbers, stored in a file, represent a particular coding of a frieze, and
- either display the period of the pattern of the frieze and the transformations that keep it invariant, based on a result that classifies friezes into 7 groups of symmetries,
- or output some Latex code in a file, from which a pictorial representation of the frieze can be produced.

The representation of a frieze is based on a coding with numbers in the range 0 15, each such number n being associated with a particular point p such that

- if the rightmost digit of the representation of n in base 2 is equal to 1 then p is to be connected to its northern neighbour:
- if the second rightmost digit of the representation of n in base 2 is equal to 1 then p is to be connected to its north-eastern neighbour:
- if the third rightmost digit of the representation of n in base 2 is equal to 1 then p is to be connected to its eastern neighbour:
- if the fourth rightmost digit of the representation of n in base 2 is equal to 1 then p is to be connected to its south-eastern neighbour:

## Examples

### First example

The file frieze_1.txt has the following contents.

Here is a possible interaction:

1 | from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_1.tex that can be given as argument to pdflatex to produce a file named frieze_1.pdf that views as follows.

### Second example

The file frieze_2.txt has the following contents.

Here is a possible interaction:

1 | >>> from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_2.tex that can be given as argument to pdflatex to produce a file named frieze_2.pdf that views as follows.

### Third example

The file frieze_3.txt has the following contents.

Here is a possible interaction:

1 | >>> from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_3.tex that can be given as argument to pdflatex to produce a file named frieze_3.pdf that views as follows.

### Fourth example

The file frieze_4.txt has the following contents.

Here is a possible interaction:

1 | from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_4.tex that can be given as argument to pdflatex to produce a file named frieze_4.pdf that views as follows.

### Fifth example

The file frieze_5.txt has the following contents.

Here is a possible interaction:

1 | >>> from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_5.tex that can be given as argument to pdflatex to produce a file named frieze_5.pdf that views as follows.

### Sixth example

The file frieze_6.txt has the following contents.

Here is a possible interaction:

1 | from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_6.tex that can be given as argument to pdflatex to produce a file named frieze_6.pdf that views as follows.

### Seventh example

The file frieze_7.txt has the following contents.

Here is a possible interaction:

1 | from frieze import * |

The effect of executing `frieze.display()`

is to produce a file named frieze_7.tex that can be given as argument to pdflatex to produce a file named frieze_7.pdf that views as follows.

## Detailed description

### Input

The input is expected to consist of `height + 1`

lines of `length + 1`

numbers in {0, …, 15}, where length is at least equal to 4 and at most equal to 50 and height is at least equal to 2 and at most equal to 16, with possibly lines consisting of spaces only that will be ignored and with possibly spaces anywhere on the lines with numbers. The xth number n of the y th line, with 0 x length and 0 y height,

- is to be associated with a point situated x ? 0.2 cm to the right and y? 0.2 cm below an origin,
- is to be connected to the point 0.2 cm above if the rightmost digit of n is 1,
- is to be connected to the point 0.2 cm above and 0.2 cm to the right if the second rightmost digit of n is 1,
- is to be connected to the point 0.2 cm to the right if the third rightmost digit of n is 1, and
- is to be connected to the point 0.2 cm to the right and 0.2 cm below if the fourth rightmost digit of n is 1.

To qualify as a frieze, the input is further constrained to fit in a rectangle of length length ? 0.2 cm and of height heigth ? 0.2 cm, with horizontal lines of length length at the top and at the bottom, identical vertical borders at both ends, no crossing segments connecting pairs of neighbours inside the rectangle, and a pattern of integral period at least equal to 2 that is fully repeated at least twice in the horizontal dimension.

### Output

Consider executing from the Python prompt the statement `from frieze import * followed`

by the statement `frieze = Frieze(some_filename)`

. In case some_filename does not exist in the working directory, then Python will raise a FileNotFoundError exception, that does not need to be caught. Assume that some_filename does exist (in the working directory). If the input is incorrect in that it does not contain only numbers in {0, . . . , 15} besides spaces, or in that it contains either too few or too many lines of numbers, or in that some line of numbers contains too many or too few numbers, or in that two of its lines of numbers do not contain the same number of numbers, then the effect of executing `frieze = Frieze(some\_filename)`

should be to generate a FriezeError exception that reads

```
Traceback (most recent call last):
...
frieze.FriezeError: Incorrect input.
```

If the previous conditions hold but the further conditions spelled out above for the input to qualify as a frieze do not hold, then the effect of executing `frieze = Frieze(some_filename)`

should be to generate a FriezeError exception that reads

```
Traceback (most recent call last):
...
frieze.FriezeError: Input does not represent a frieze.
```

If the input is correct and represents a frieze, then executing `frieze = Frieze(some_filename)`

followed by `frieze.analyse()`

should have the effect of outputting one or two lines that read

Pattern is a frieze of period N that is invariant under translation only. or

Pattern is a frieze of period N that is invariant under translation and vertical reflection only. or

Pattern is a frieze of period N that is invariant under translation and horizontal reflection only. or

Pattern is a frieze of period N that is invariant under translation and glided horizontal reflection only. or

Pattern is a frieze of period N that is invariant under translation and rotation only. or

Pattern is a frieze of period N that is invariant under translation, glided horizontal and vertical reflections, and rotation only. or

Pattern is a frieze of period N that is invariant under translation, horizontal and vertical reflections, and rotation only. with N an appropriate integer at least equal to 2.

These 7 possible outputs are based on a mathematical result on the classification of friezes that lists all possible complete lists of symmetries that leave a frieze invariant under an isometry (that is, a transformation that does not alter the distance between any two points). These possible lists involve 5 symmetries.

- Translation by period; of course, any frieze is invariant under this symmetry.
- Vertical reflection about some vertical line; that line does not necessarily delimit the pattern nor does it necessarily go through its middle (these conditions are actually equivalent).
- Horizontal reflection about the line that goes through the middle of the frieze.
- Glided horizontal reflection, that is, horizontal reflection about the line that goes through the middle of the frieze and translation by half the period of the resulting lower half of the frieze.
- Rotation around some point situated on the horizontal line that goes through the middle of the frieze; this is equivalent to horizontal refection combined with vertical reflection.

Pay attention to the expected format, including spaces.

If the input is correct and represents a frieze, then executing `frieze = Frieze(some_filename)`

followed by `frieze.display()`

should have the effect of producing a file named some_filename.tex that can be given as argument to pdflatex to generate a file named some_filename.pdf. The provided examples will show you what some_filename.tex should contain. Segments are drawn in purple with a single draw command for each longest segment,

- starting with the vertical segments, from the topmost leftmost one to the bottommost rightmost one with the leftmost ones first,
- followed by the segments that go from north west to south east, from the topmost leftmost one to the bottommost rightmost one with the topmost ones first,
- followed by the segments that go from west to east, from the topmost leftmost one to the bottommost rightmost one with the topmost ones first,
- followed by the segments that go from the south west to the north east, from the topmost leftmost one to the bottommost rightmost one with the topmost ones first.

Pay attention to the expected format, including spaces and blank lines. Lines that start with % are comments; there are 4 such lines, that have to be present even when there is no item to be displayed of the kind described by the comment. The output of your program redirected to a file will be compared with the expected output saved in a file (of a different name of course) using the diff command. For your program to pass the associated test, diff should silently exit, which requires that the contents of both files be absolutely identical, character for character, including spaces and blank lines. When testing locally, check your program on the provided examples using the associated .tex files, renaming them as they have the names of the files expected to be generated by your program.