Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added a shorter version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), 59 bytes

We can save 2 bytes by making the sequence 1-indexed and using a simplification similar to the one used by KSab :

n=>(x=g=y=>n?g(y+=y==(x^=y-x),n--):x<y?[x++,...g(y)]:[])(1)

Try it online!


#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\operatorname{AND}-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\operatorname{AND}-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

#JavaScript (ES6), 59 bytes

We can save 2 bytes by making the sequence 1-indexed and using a simplification similar to the one used by KSab :

n=>(x=g=y=>n?g(y+=y==(x^=y-x),n--):x<y?[x++,...g(y)]:[])(1)

Try it online!


#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\operatorname{AND}-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

added 6 characters in body
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\text{ AND }-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\operatorname{AND}-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\text{ AND }-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\operatorname{AND}-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

added the 'How?' section
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\text{ AND }-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

#JavaScript (ES6), 61 bytes

Returns a list of non-wrapping integers.

n=>(g=v=>n?g(u&-u^v?v*2:!!u++,n--):v?[u-v,...g(v-1)]:[])(u=1)

Try it online!

Based upon a construction by Donald Knuth. Related OEIS entry: A182105.

###How?

This is a two-stage recursive function.

We first build the sequence \$(u_n,v_n)\$ defined as \$(u_1,v_1)=(1,1)\$ and:

$$(u_{n+1},v_{n+1})=\begin{cases}(u_{n}+1,1),&\text{if }(u_{n}\text{ AND }-u_{n})=v_{n}\\(u_{n},2v_{n}),&\text{otherwise}\end{cases}$$

During the second pass, we build the list \$[u_n-v_n,u_n-v_n+1,\dots,u_n]\$ and eventually return it.


#JavaScript (ES6), 97 bytes

Returns wrapping uppercase letters.

n=>(s=i='',g=v=>(s+=String.fromCharCode(65+i++%26),n--)?g(u&-u^v?v*2:!!u++):s.substr(u-v,v))(u=1)

Try it online!

Or 91 bytes in lowercase.

saved 3 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 8 bytes on the alternate version, 10 bytes on the other ones
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
added an alternate version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

AltStyle によって変換されたページ (->オリジナル) /