Post History
JavaScript (Node.js), 73 66 bytes This returns a Generator, which calculates the sequence on the fly when you use it! function*f(a){while(a>1){yield a a=~~(a%2?a**1.5:a**0.5)} yield a} Or...
Answer
#3: Post edited
## JavaScript (Node.js), 73 bytes- This returns a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators), which calculates the sequence on the fly when you use it!
- ```js
- function*f(a){while(1){yield a
- if(a==1){return}
- a=~~(a%2?a**1.5:a**0.5)}}
- ```
- To use it, do something like this, which calculates the whole thing and makes it into an array.
- ```js
- [...f(5)] // returns [ 5, 11, 36, 6, 2, 1 ]
- ```
- ---
- Explanation:
- ```js
- function* f(a) { // makes a generator function
while (1) {- yield a // return this bit of the sequence
if (a == 1) {return // are we done? stop}- a = ~~( // truncates the decimals? apparently? and it's shorter than Math.floor()/Math.trunc()
- a%2 ? a**1.5 : a**0.5
- )
- }
- }
- ```
- ## JavaScript (Node.js), <del>73</del> 66 bytes
- This returns a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators), which calculates the sequence on the fly when you use it!
- ```js
- function*f(a){while(a>1){yield a
- a=~~(a%2?a**1.5:a**0.5)}
- yield a}
- ```
- Original, more aesthetically pleasing but slightly longer version:
- ```js
- function*f(a){while(1){yield a
- if(a==1){return}
- a=~~(a%2?a**1.5:a**0.5)}}
- ```
- To use it, do something like this, which calculates the whole thing and makes it into an array.
- ```js
- [...f(5)] // returns [ 5, 11, 36, 6, 2, 1 ]
- ```
- ---
- Explanation:
- ```js
- function* f(a) { // makes a generator function
- while (a > 1) {
- yield a // return this bit of the sequence
- a = ~~( // truncates the decimals? apparently? and it's shorter than Math.floor()/Math.trunc()
- a%2 ? a**1.5 : a**0.5
- )
- }
- yield a // return the final 1
- }
- ```
#2: Post edited
- ## JavaScript (Node.js), 73 bytes
- This returns a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators), which calculates the sequence on the fly when you use it!
```- function*f(a){while(1){yield a
- if(a==1){return}
- a=~~(a%2?a**1.5:a**0.5)}}
- ```
- To use it, do something like this, which calculates the whole thing and makes it into an array.
```- [...f(5)] // returns [ 5, 11, 36, 6, 2, 1 ]
- ```
- ---
- Explanation:
```- function* f(a) { // makes a generator function
- while (1) {
- yield a // return this bit of the sequence
- if (a == 1) {
- return // are we done? stop
- }
- a = ~~( // truncates the decimals? apparently? and it's shorter than Math.floor()/Math.trunc()
- a%2 ? a**1.5 : a**0.5
- )
- }
- }
- ```
- ## JavaScript (Node.js), 73 bytes
- This returns a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators), which calculates the sequence on the fly when you use it!
- ```js
- function*f(a){while(1){yield a
- if(a==1){return}
- a=~~(a%2?a**1.5:a**0.5)}}
- ```
- To use it, do something like this, which calculates the whole thing and makes it into an array.
- ```js
- [...f(5)] // returns [ 5, 11, 36, 6, 2, 1 ]
- ```
- ---
- Explanation:
- ```js
- function* f(a) { // makes a generator function
- while (1) {
- yield a // return this bit of the sequence
- if (a == 1) {
- return // are we done? stop
- }
- a = ~~( // truncates the decimals? apparently? and it's shorter than Math.floor()/Math.trunc()
- a%2 ? a**1.5 : a**0.5
- )
- }
- }
- ```
#1: Initial revision
## JavaScript (Node.js), 73 bytes This returns a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators), which calculates the sequence on the fly when you use it! ``` function*f(a){while(1){yield a if(a==1){return} a=~~(a%2?a**1.5:a**0.5)}} ``` To use it, do something like this, which calculates the whole thing and makes it into an array. ``` [...f(5)] // returns [ 5, 11, 36, 6, 2, 1 ] ``` --- Explanation: ``` function* f(a) { // makes a generator function while (1) { yield a // return this bit of the sequence if (a == 1) { return // are we done? stop } a = ~~( // truncates the decimals? apparently? and it's shorter than Math.floor()/Math.trunc() a%2 ? a**1.5 : a**0.5 ) } } ```