Skip to main content
added 3 characters in body
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]\$[1,N^k]+[0]\$) with each result reversed.

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]) with each result reversed.

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values \$[1,N^k]+[0]\$) with each result reversed.

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N
added 26 characters in body
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]) with each result reversed.

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]).

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]) with each result reversed.

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N
added 207 characters in body
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]).

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N

Jelly, 6 bytes

ṗ@Ż€I%

A dyadic Link that accepts the length, \$k\$, on the left and the number of symbols, \$N\$ on the right and yields a list of lists of non-negative integers.

Try it online!

How?

This is the same cyclic Gray code that the algorithm displayed on Wikipedia will produce (for values [1..N]+[0]).

ṗ@Ż€I% - Link: k, N
 @     - with swapped arguments:
ṗ      -   [1..N] Cartesian product [1..k]
  Ż€   - prefix a zero to each
    I  - incremental differences
     % - modulo N
added 226 characters in body
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282
Loading
Source Link
Jonathan Allan
  • 110.2k
  • 7
  • 65
  • 282
Loading