Éric Angelini devised this progressively self-inventorying array:
10 71 32 23 14 15 16 27 18 19
20 81 72 53 44 35 26 47 38 29
40 101 82 73 64 65 56 77 58 39
60 131 92 93 74 75 86 107 88 69
80 201 122 113 84 85 96 117 138 89
The first line describes it own contents: it contains one occurrence of the digit 0, seven occurrences of the digit 1, three occurrences of the digit 2, two occurrences of the digit 3, and so on.
In the same style, the second line describes the joint contents of the first and the second lines: they contain two occurrences of the digit 0, eight occurrences of the digit 1, seven occurrences of the digit 2, five occurrences of the digit 3, and so on.
The remaining lines also describe their own contents and that of all previous lines. The fifth line describes the contents of all lines: together they contain eight occurrences of the digit 0, twenty occurrences of the digit 1, twelve occurrences of the digit 2, eleven occurrences of the digit 3, and so on.
He suspects that a six-line self-inventorying array is possible, but he hasn't found one yet.
The digit count of string $$s$$ (str) is a tuple containing ten numbers $$(a_0, a_1, \ldots, a_9)$$, with $$a_i \in \mathbb{N}$$ (int) the number of occurrences of digit $$i$$ in $$s$$ ($$i = 0, 1, \ldots, 9$$).
The description of a digit count $$(a_0, a_1, \ldots, a_9)$$ is a string (str) formatted as
$$a_0$$0 $$a_1$$1 $$\ldots$$ $$a_9$$9
Leading zeros in the representation of $$a_i$$i ($$i = 0, 1, \ldots, 9$$) are omitted: if digit 3 does not occur in string $$s$$, then the description of the digit count simply mentions 3 and not 03. Your task:
Write a function digit_count that takes a string (str). The function must return the digit count of the given string.
Write a function description that takes the digit count of a string. The function must return the description of the given digit count.
Write a function isselfinventorying that takes a sequence (list or tuple) of $$n \in \mathbb{N}$$ strings (str). The function must return a Boolean value (bool) that indicates if the $$n$$ strings are a self-inventorying array. This is the case if each $$i$$-the string is the description of the joint contents of the first $$i$$ strings ($$i = 1, 2, \ldots, n$$).
An empty sequence is self-inventorying by definition.
Write a function isselfinventorying_2 that takes a variable number of $$n \in \mathbb{N}$$ strings (str). The function must return a Boolean value (bool) that indicates if the $$n$$ strings are a self-inventorying array. This is the case if each $$i$$-the string is the description of the joint contents of the first $$i$$ strings ($$i = 1, 2, \ldots, n$$).
>>> digit_count('10 71 32 23 14 15 16 27 18 19')
(1, 7, 3, 2, 1, 1, 1, 2, 1, 1)
>>> digit_count('F1gur471v3ly 5p34k1ng?')
(0, 3, 0, 2, 2, 1, 0, 1, 0, 0)
>>> description((1, 7, 3, 2, 1, 1, 1, 2, 1, 1))
'10 71 32 23 14 15 16 27 18 19'
>>> description((0, 3, 0, 2, 2, 1, 0, 1, 0, 0))
'0 31 2 23 24 15 6 17 8 9'
>>> isselfinventorying(['10 71 32 23 14 15 16 27 18 19'])
True
>>> isselfinventorying(['F1gur471v3ly 5p34k1ng?'])
False
>>> isselfinventorying([
... '10 71 32 23 14 15 16 27 18 19',
... '20 81 72 53 44 35 26 47 38 29'
... ])
True
>>> isselfinventorying((
... '10 71 32 23 14 15 16 27 18 19',
... '20 81 72 53 44 35 26 47 38 29',
... '40 101 82 73 64 65 56 77 58 39',
... '60 131 92 93 74 75 86 107 88 69',
... '80 201 122 113 84 85 96 117 138 89',
... ))
True
>>> isselfinventorying_2('10 71 32 23 14 15 16 27 18 19')
True
>>> isselfinventorying_2('F1gur471v3ly 5p34k1ng?')
False
>>> isselfinventorying_2(
... '10 71 32 23 14 15 16 27 18 19',
... '20 81 72 53 44 35 26 47 38 29'
... )
True
>>> isselfinventorying_2(
... '10 71 32 23 14 15 16 27 18 19',
... '20 81 72 53 44 35 26 47 38 29',
... '40 101 82 73 64 65 56 77 58 39',
... '60 131 92 93 74 75 86 107 88 69',
... '80 201 122 113 84 85 96 117 138 89',
... )
True
Éric Angelini may stop looking for six-line self-inventorying arrays, as Toon Baeyens from Ghent University was able to demonstrate that such an array does not exist. In addition, he also showed that apart from the five-line self-inventorying array from the introduction, there is only one other such array:
10 71 32 23 14 15 16 27 18 19
20 81 72 53 44 35 26 47 38 29
30 111 82 83 74 45 46 77 68 39
40 151 92 93 94 75 56 117 78 79
60 241 112 113 114 85 76 137 108 89
At least, as long as we restrict ourselves to the decimal number system.