When reading out these digital seven-segment displays, the digits on the fifth row have been obscured. What are they?

readouts
When reading out these digital seven-segment displays, the digits on the fifth row have been obscured. What are they?

They are the same as the digits in the first row. We have added colors to the segments of the digits on the two top rows, to make it easier to see that the digits on a given row count how many segments of each type (color) occur in the previous row. Remarkably, this is the only loop that already repeats itself after four steps.

readouts
The digits in the bottom row are the same as the digits in the first row. The segments of the digits on the two top rows are colored, to make it easier to see that the digits on a given row count how many segments of each type (color) occur in the previous row. Remarkably, this is the only loop that repeats already itself after four steps.

Assignment

As the name already suggests, a seven-segment display is a form of electronic display device that uses seven segments to render decimal digits. If all seven segments are on, they render the number 8. The segments are numbered starting from zero in the usual reading order: from left to right and from top to bottom.

segments
Numbering of the seven segments of a seven-segment display.

By switching specific segments on or off, the ten decimal digits are rendered on a display in the following way.

digits
Rendering of the ten decimal digits on a seven-segment display.

Here, segments that are on are shown in red. Note that the digit 1 is rendered by only turning on the two segments on the left, not the two segments on the right. This is a detail that is important in view of what follows.

The rendering of a digit on a seven-segment display is represented as a set with the numbers (int) of the segments that are turned on. For example, the rendering of digit 3 on a seven-segment display is represented as the set $$\{0, 2, 3, 5, 6\}$$. These segments are turned on on a seven-segment display to render each of the ten decimal digits:

digit segments
0 0, 1, 2, 4, 5, 6
1 1, 4
2 0, 2, 3, 4, 6
3 0, 2, 3, 5, 6
4 1, 2, 3, 5
5 0, 1, 3, 5, 6
6 0, 1, 3, 4, 5, 6
7 0, 2, 5
8 0, 1, 2, 3, 4, 5, 6
9 0, 1, 2, 3, 5, 6

A readout $$r = r_0r_1r_2r_3r_4r_5r_6$$ of seven digits on seven seven-segment displays is represented as a string (str) of the seven digits. For each readout $$r$$ we can determine the next readout $$s = s_0s_1s_2s_3s_4s_5s_6$$, where $$s_i$$ ($$i = 0, \ldots, 6$$) counts how often segment $$i$$ is on in the rendering of the digits of readout $$r$$.

Your task:

Example

>>> digit2segments(3)
{0, 2, 3, 5, 6}
>>> digit2segments('A')
Traceback (most recent call last):
AssertionError: invalid digit

>>> segments2digit({0, 5, 2, 6, 3})
3
>>> segments2digit([2, 3, 5])
Traceback (most recent call last):
AssertionError: invalid segments

>>> next_readout('4635263')
'6447366'
>>> next_readout('6447366')
'5546374'
>>> next_readout('5546374')
'5546174'
>>> next_readout('5546174')
'4635263'
>>> cycle('ABCDEFG')
Traceback (most recent call last):
AssertionError: invalid readout

>>> cycle('4635263')
['4635263', '6447366', '5546374', '5546174']
>>> cycle('4436426')
['4436426', '4557364', '5546174', '4635263', '6447366', '5546374']
>>> cycle('ABCDEFG')
Traceback (most recent call last):
AssertionError: invalid readout