Skip to main content
4 of 4
added 105 characters in body; edited title

Output the Juggler sequence

The Juggler sequence is described as follows. Beginning with an input \$a_1\$, the next term is defined by the recurrence relation

$$a_{k+1} = \begin{cases} \left\lfloor a_k ^ \frac 1 2 \right\rfloor,\text{ if } a_k \text{ is even} \\ \left\lfloor a_k ^ \frac 3 2 \right\rfloor,\text{ if } a_k \text{ is odd} \\ \end{cases}$$

The sequence terminates when it reaches 1, as all subsequent terms would then be 1.

Task

Given an input \$n\$ greater than or equal to 2, write a program/function/generator/etc. that outputs/returns the respective juggler sequence. The output can be in any reasonable form. You may not use a built-in that computes the juggler sequence, or any built-in that directly yields the result. You may assume that the sequence terminates in \$1\$.

Test Cases

Input: output
2: 2, 1
3: 3, 5, 11, 36, 6, 2, 1
4: 4, 2, 1
5: 5, 11, 36, 6, 2, 1

This is a code golf. Shortest code in bytes wins.

Seadrus
  • 1.4k
  • 11
  • 24