Charcoal, 30 2929 28 bytes
NθNηIEXθηE﹪÷ιXθ⮌…⁰η⊗θ⌊⟦⁻⊖⊗θλλNθNηIEXθηE÷ιXθ⮌…⁰η⌊﹪⟦⊖±λλ⟧⊗θ
Try it online!Try it online! Link is to verbose version of code. Outputs each digit of the gray code as a base 10 number on its own line, with each gray code double-spaced from the next. Explanation:
Nθ Input `N` as a number
Nη Input `k` as a number
θ Input `N`
X To the power of
η Input `k`
E Map over implicit range
ι Current value
÷ Vectorised integer divide
θ Input `N`
X Vectorised to power
… Range from
⁰ Literal integer `0`
η To input `k`
⮌ Reversed
﹪ Vectorised modulo
θ Input `N`
⊗ DoubledReversed
E Map over list
λ θ InputCurrent `N`value
± ⊗ DoubledNegated
⊖ Decremented
⁻ Subtract
λ Current valueDecremented
⟦ ⌊⟦ ⟧ MinimumList of that and
λ Current value
I Cast to string
Implicitly print
If omission of leading zeros is allowed then for 28 bytes:
NθNηIEEXθη↨ιθEι⎇﹪↨…ιμθ²⁻⊖θλλ
Try it online! Link is to verbose version of code. Explanation:
Nθ Input `N` as a number
Nη Input `k` as a number
θ Input `N`
X To the power of
η Input `k`
E Map over implicit range
ι Current value
↨ Converted to base
θ Input `N`
E Map over base `N` values
ι Current base `N` value
E Map over base `N` digits
…ιμ Current prefix
↨ Convert from base
θ Input `N`
﹪ Modulo
² Literal integerVectorised `2`modulo
⎇ If odd then
θ Input `N`
⊖ Decremented
⁻ Subtract
λ ⊗ Current digitDoubled
⌊ λ ElseTake currentthe digitminimum
I Cast to string
Implicitly print
(Note that all leading zeros are omitted, so the first gray code is empty.)