# [Charcoal], <s>30</s> 29 bytes NθNηIEXθηE﹪÷ιXθ⮌…⁰η⊗θ⌊⟦⁻⊖⊗θλλ [Try it online!][TIO-l0jf17wv] 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` ⊗ Doubled E Map over list θ Input `N` ⊗ Doubled ⊖ Decremented ⁻ Subtract λ Current value ⌊⟦ Minimum of that and λ Current value ⮌ Reversed I Cast to string Implicitly print If omission of leading zeros is allowed then for 28 bytes: NθNηIEEXθη↨ιθEι⎇﹪↨…ιμθ²⁻⊖θλλ [Try it online!][TIO-l0jeexrb] 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 integer `2` ⎇ If odd then θ Input `N` ⊖ Decremented ⁻ Subtract λ Current digit λ Else current digit I Cast to string Implicitly print (Note that *all* leading zeros are omitted, so the first gray code is empty.) [Charcoal]: https://github.com/somebody1234/Charcoal [TIO-l0jf17wv]: https://tio.run/##TYzNCoMwEITvfYocV0ihiDeP9eJBEekLbHXRQEzMGi19@jQp9GdhF2a/mRlm5MGiDqE26@7bfbkTg8vK07@eo@5YGQ9X3Dw0dty1hQZX6Owj@aWYMynSoza@UocaCZQUX9rTQbwR9Ggmgkuyx5HiRmyQn5/GX1hL4SLP41Y0MC1kPI3Q0oQ@0pTV7wYXbxlCIYpwPvQL "Charcoal – Try It Online" [TIO-l0jeexrb]: https://tio.run/##TYu9DsMgEIP3PgXjIdGlypatdOmQKkNf4EpOAolAwk@rPD0FutSSJVv@rDQG5dGWcndbTo@8vijAzsfTf9e1z8G4BBJjggm37tl/GiyY5oJdMRIYwfaa21jjk4LDcMDkl2w9dEIeypLUvgMr//GX9jEuR7iRCrSSS7RAW2x301jKwIZyftsv "Charcoal – Try It Online"