Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

71%
+3 −0
Challenges Juggler sequences

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

posted 3y ago by forestbeasts‭  ·  edited 3y ago by forestbeasts‭

Answer
#3: Post edited by user avatar forestbeasts‭ · 2021-05-29T18:10:32Z (over 3 years ago)
Slightly shorter solution!
  • ## 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 by user avatar forestbeasts‭ · 2021-05-29T01:52:06Z (over 3 years ago)
Language-tag the code blocks for (hopefully) proper syntax highlighting
  • ## 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 by user avatar forestbeasts‭ · 2021-05-29T01:51:05Z (over 3 years ago)
## 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
		)
	}
}
```