Python 2, 62 6161 58 bytes
lambda n:[5**int[5**(nn*3/.7-~i)/10**n%10for2**n%10for i in range(2**n/2)]or2or 51)]
0 5[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, 9L9, 5L5, 8L8, 2L2, 2L2, 4L4, 2L, 1L, 6L, 3L3
L, 6L, 0L, 0L]
7 [4, 4, 2, 0, 1, 8, 3, 9, 8, 3, 5, 9, 5, 7, 7, 8, 2, 1L1, 9L9, 7L7, 9L9, 6L6, 1L1, 7L7, 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]
AlternativePrevious solution, also 61 bytes:
lambda n:[5**int(n/.7-~i)/10**n%10for i in range(2**n/2or 1)]
lambda n:[str(5**int(n/.7-~i))[~n]for i in range(2**n/2)]or 5
def f(n):
if n == 0:
return 5
r = max(2**n / 2
d = 10**n, 1)
m = int(n/0.7 + 1)
for i in range(r):
yield (5**(m+i) /d 10**n) % 10
The range(2**n/2)
uses the observation that each cycle has length Rr = 2n-1 except when n = 0, so we just compute the n-th digits for 5m to 5m + r - 1.
The / d10**n % 10
in the loop simply extract the desired digit. TheAnother alternative solution uses string manipulation. I used the trick ~n == -n-1
here to remove 1 byte.
When n = 0An mentioned in the comment, the loop will give an empty listexpression 5**(m+i) / 10**n
can further be simplified this way, so we special-case it by returningwhich gives the hardcurrent 58-coded "5" when the list is emptybyte answer.
(The division x/2**n
can be done using bitwise right-shift x>>n
. Unfortunately, due to Python's operator precedence this does not save any bytes.) The fraction 3/7 can also be improved in similar mannar:
| approximation | valid until | penalty |
|---------------------------------|---------------------|-----------|
| n*3/7 | n = 72 | +0 bytes |
| n*31/72 | n = 137 | +2 bytes |
| n*59/137 | n = 476 | +3 bytes |
| n*351/815 | n = 1154 | +4 bytes |
| n*643/1493 | n = 10790 | +5 bytes |
| n*8651/20087 | n = 49471 | +7 bytes |
| int(n*.43067655807339306) | too large to check | +20 bytes |
| import math;int(n/math.log2(5)) | same as above | +26 bytes |