OFFSET
0,1
COMMENTS
6, 7, and 9 each have two possible representations on a 7-segment display. Therefore, a number that contains at least one of each digit can be displayed in 8 different ways. We use 'variant 5' because it was the first one added to the OEIS (A006942).
This sequence is interesting because a(n) is guaranteed to exist for n>=1. For instance, printing a '6' will always result in 1 unused segment. If we want to get a number that returns m unused segments, then we can always return '66...66' with '6' appearing m times. This also provides an upper bound for the value of a(n). Despite this, the value of a(n) for a given n is nontrivial.
This sequence does not increase monotonically.
Certain digits can never appear in the sequence for n>=1:
- 8: This digit contributes 0 unused segments. If a solution contains an 8 and has more than one digit, the 8 can be removed entirely without reducing the number of unused segments, resulting in a smaller number. The only exception is when the number is a single digit, so for a(0).
- 3 and 5: Both use the same number of segments as 2. So, if a solution includes a 3 or 5, we can replace it with a 2 without changing the number of unused segments, but the overall number would be smaller.
- 9: Same as above: any 9 can be replaced by a 6. We can't extend this to 0 (same number of segments as 6 or 9), because we can't always swap a 6 or a 9 for a 0 (e.g. '600').
Among all 10 digits, 1 has the largest number of unused segments (5). As a consequence, when n = 5*p (with p>=1), a(n) = '1..1' with 1 appearing p times because if a(n) contained any other digit, it would be more than p digits long, and would thus not be optimal.
The next term a(5*p+1) necessarily has an additional digit. The smallest digit that adds only 1 unused segment is 0 but it cannot be placed in the leading position. The next best position is the second one, thus a(5*p+1) = '10...1' with p 1s and a single 0.
To construct the next term a(5*p+2), we swap the existing zero for another digit with an additional unused segment (2 being optimal as it is the smallest) and move it to the trailing position (to yield the smallest possible number). Hence a(5*p+2) = '1..12' with p 1s and a single 2. Any other approach, such as adding an extra 0 or swapping a 1 for something else, would result in a solution with more than p+1 digits and would thus not be optimal.
The next two terms can be constructed the same way, yielding a(5*p+3) = '1..14' and a(5*p+4) = '1..17' with again p+1 digits in total. We then loop back to the beginning with a(5*p+5).
LINKS
Index entries for linear recurrences with constant coefficients, signature (0,0,0,0,11,0,0,0,0,-10).
FORMULA
For p>=1:
a(5*p) = (10^p-1)/9
a(5*p+1) = (91*10^(p-1)-1)/9
a(5*p+2) = (10^(p+1)-1)/9 + 1
a(5*p+3) = (10^(p+1)-1)/9 + 3
a(5*p+4) = (10^(p+1)-1)/9 + 6
EXAMPLE
a(1) is the smallest number with exactly 1 unused segment. The digit 0 uses 6 segments, leaving 1 unused, and since 0 is the smallest valid number, we have a(1) = 0.
For a(6), we seek the smallest number with exactly 6 unused segments. No single-digit number meets this, as each digit leaves at most 5 segments unused. Among two-digit numbers, 10 is the smallest: '1' contributes 5 unused segments and '0' contributes 1, totaling 6. Therefore, a(6) = 10.
PROG
(Python)
def a(n):
q, r = divmod(n, 5)
if q == 0:
return [8, 0, 2, 4, 7][r]
if r == 0:
return 10**q//9
if r == 1:
return 91*10**(q-1)//9
return 10**(q+1)//9 + [1, 3, 6][r - 2]
CROSSREFS
KEYWORD
base,nonn,easy
AUTHOR
Renaud Gaudron, May 12 2025
STATUS
approved
