Skip to main content
deleted 1868 characters in body
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

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`
                    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.)

Charcoal, 30 29 bytes

NθNηIEXθηE﹪÷ιXθ⮌…⁰η⊗θ⌊⟦⁻⊖⊗θλλ

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`
                               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! 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, 30 29 28 bytes

NθNηIEXθηE÷ιXθ⮌…⁰η⌊﹪⟦⊖±λλ⟧⊗θ

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
         E                      Map over list
                       λ        Current value
                      ±         NegatedDecremented
                              List of that and
                        λ       Current value
                   ﹪            Vectorised modulo
                           θ    Input `N`
                               Doubled
                               Take the minimum
    I                           Cast to string
                                Implicitly print
removed bogus line of explanation
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281
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
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
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
forgot to update TIO link
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

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:

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:

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:

deleted 99 characters in body
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281
Loading
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281
Loading