# [Charcoal], <s>30</s> 29 bytes NθNηIEXθηE﹪÷ιXθ⮌…⁰η⊗θ⌊⟦⁻⊖⊗θλλ [Try it online!][TIO-l0jrr3xr] 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 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-l0jrr3xr]: https://tio.run/##VY27CsMwDEX3foVHGVzokC1jvWRICVlLB8cWtcGP1I/08117Ka1AoCudeyW1iDIIW@vk95JvxW0Y4UXH06/WTS/R@AxXkTLMYoclvDvIiKaM9MUcVLEBJp@5OYxCMIx8oRUPjAlhFf6JcOmuVozwUDaLqj3sKcYbVxzc21AScJQRHfrc7n@c7f3oAXSsdSBDPR/2Aw "Charcoal – Try It Online" [TIO-l0jeexrb]: https://tio.run/##TYu9DsMgEIP3PgXjIdGlypatdOmQKkNf4EpOAolAwk@rPD0FutSSJVv@rDQG5dGWcndbTo@8vijAzsfTf9e1z8G4BBJjggm37tl/GiyY5oJdMRIYwfaa21jjk4LDcMDkl2w9dEIeypLUvgMr//GX9jEuR7iRCrSSS7RAW2x301jKwIZyftsv "Charcoal – Try It Online"