Perl 6, 52 bytes
->\n{(map {.comb[*-n]//|()},(5 X**1..*))[^(2**n/4)]}
Works for allarbitrarily high inputs, given enough RAMsufficient memory (i.e. doesn't useno logarithm approximation).
Returns a list of digits.
How it works
->\n{ } # A lambda with argument n.
(5 X**1..*) # The sequence 5, 25, 125, 625...
map { }, # Transform each element as such:
.comb[*-n] # Extract the n'th last digit,
//|() # or skip it if that doesn't exist.
( )[^(2**n/4)] # Return the first 2^(n-2) elements.
The "element skipping" part works like this:
- Indexing a list at an illegal index returns a Failure, which counts as an "undefined" value.
//
is the "defined or" operator.|()
returns an empty Slip, which dissolves into the outer list as 0 elements, essentially making sure that the current element is skipped.
The edge-case n=1
works out fine, because 2**n/4
becomes 0.5
, and ^(0.5)
means 0 ..^ 0.5
a.k.a. "integers between 0 (inclusive) and 0.5 (not inclusive)", i.e. a list with the single element 0.