Output the juggler sequence
Julia, 64 50 48 42 32 30 bytes
g(x)=[x;x<3||g(x^(x%2+.5)÷1)]
This is a recursive function that accepts an integer and returns a float array.
We build an array by concatenating the input with the next term of the sequence, computed as x to the power of its parity plus 1/2. This gives us either x1/2 or x1+1/2 = x3/2. Integer division by 1 gets the floor. When the condition x < 3 is true, the final element will be a Boolean rather than a numeric value, but since the array is not of type Any
, this is cast to have the same type as the rest of the array.
Saved 14 bytes thanks to Dennis!
Jelly, 12 11 10 bytes
*BṪ×½Ḟµ’п
Thanks to @Sp3000 for golfing off 1 byte!
Try it online!
How it works
*BṪ×½Ḟµ’п Main link. Input: n
*B Elevate n to all of its digits in base 2.
Ṫ Extract the last power.
This yields n ** (n % 2).
×½ Multiply with sqrt(n). This yields n ** (n % 2 + 0.5).
Ḟ Floor.
µ Push the previous chain on the stack and begin a new, monadic chain.
п Repeat the previous chain while...
’ n - 1 is non-zero.
Collect all intermediate results in an array.
JavaScript (ES7), 45 33 bytes
f=n=>n<2?n:n+","+f(n**(.5+n%2)|0)
Explanation
Recursive approach. Returns a comma-separated string of numbers.
f=n=>
n<2?n: // stop when n == 1
n // return n at the start of the list
+","+f( // add the rest of the sequence to the list
n**(.5+n%2)|0 // juggler algorithm
)
Test
**
not used in test for browser compatibility.
f=n=>n<2?n:n+","+f(Math.pow(n,.5+n%2)|0)
<input type="number" oninput="result.textContent=f(+this.value)" />
<pre id="result"></pre>