Python 2, 62 61 bytes
Zero-based. I assume the L suffixes are acceptable.
lambda n:[5**int(n/.7-~i)/10**n%10for i in range(2**n/2)]or 5
Output:
0 [5]
1 [2]
2 [1, 6]
3 [3, 5, 8, 0]
4 [1, 7, 9, 5, 6, 2, 4, 0]
5 [3, 9, 7, 8, 1, 7, 5, 5, 8, 4, 2, 3, 6, 2, 0, 0]
6 [1, 9, 8, 4, 0, 3, 7, 7, 9, 7, 6, 1, 8, 1, 5, 5, 6, 4, 3, 9L, 5L, 8L, 2L, 2L, 4L, 2L, 1L, 6L, 3L, 6L, 0L, 0L]
7 [4, 4, 2, 0, 1, 8, 3, 9, 8, 3, 5, 9, 5, 7, 7, 8, 2, 1L, 9L, 7L, 9L, 6L, 1L, 7L, 6L, 0L, 3L, 6L, 3L, 5L, 5L, 5L, 9L, 9L, 7L, 5L, 6L, 3L, 8L, 4L, 3L, 8L, 0L, 4L, 0L, 2L, 2L, 3L, 7L, 6L, 4L, 2L, 4L, 1L, 6L, 2L, 1L, 5L, 8L, 1L, 8L, 0L, 0L, 0L]
Alternative solution, also 61 bytes:
lambda n:[str(5**int(n/.7-~i))[~n]for i in range(2**n/2)]or 5
Explanation:
def f(n):
if n == 0:
return 5
r = 2**n / 2
d = 10**n
m = int(n/.7 + 1)
for i in range(r):
yield (5**(m+i)/d) % 10
The range(2**n/2)
uses the observation that each cycle has length R = 2n-1, so we just compute the n-th digits for 5m to 5m + r - 1.
The start of the cycle 5m is the first number larger than 10n. Solving 5m ≥ 10n gives m ≥ n / log10 5. Here we approximate log10 5 ≈ 0.7 which will break down when n = 72. We could add more digits to increase the accuracy:
| approximation | valid until | penalty |
|---------------------------|--------------------|-----------|
| .7 | n = 72 | +0 bytes |
| .699 | n = 137 | +2 bytes |
| .69897 | n = 9297 | +4 bytes |
| .698970004 | n = 29384 | +8 bytes |
| .6989700043 | n = 128326 | +9 bytes |
| .6989700043360189 | too large to check | +15 bytes |
| import math;math.log10(5) | same as above | +23 bytes |
The / d % 10
in the loop simply extract the desired digit. The alternative solution uses string manipulation. I used the trick ~n == -n-1
here to remove 1 byte.
When n = 0, the loop will give an empty list, so we special-case it by returning the hard-coded "5" when the list is empty.