[Question]
  [
## **21, 21, 23, 20, 5, 25, 31, 24, ?**
Inspired by [this Puzzle](https://puzzling.stackexchange.com/questions/89656/what-is-the-next-number-in-the-series-21-21-23-20-5-25-31-24), given an integer \$n>0\$ , print out the following sequence until you reach a non-Integer (spoilered, in case you want to solve the puzzle yourself first)
> 
>  \$a\_0 = n\$  
> 
> \$a\_{4k+1} = a\_{4k} \cdot(4k+1) \$  
> 
> \$a\_{4k+2} = a\_{4k+1} + (4k+2)\$  
> 
> \$a\_{4k+3} = a\_{4k+2} - (4k+3)\$  
> 
> \$a\_{4k+4} = a\_{4k+3} / (4k+4)\$  
> 
> 
>  or more intuitively: \*1, +2, -3, /4, \*5, +6, -7, /8, ...
> 
> 
> 
**TestCases:**
> 
> 1: 1, 1, 3, 0, 0, 0, 6, -1  
> 
> 2: 2, 2, 4, 1  
> 
> 3: 3, 3, 5, 2  
> 
> 4: 4, 4, 6, 3  
> 
> 5: 5, 5, 7, 4, 1, 5, 11, 4  
> 
> 6: 6, 6, 8, 5  
> 
> 9: 9, 9, 11, 8, 2, 10, 16, 9  
> 
> 21: 21, 21, 23, 20, 5, 25, 31, 24, 3, 27, 37, 26
> 
> 
> 
**Input** and **Output** may be taken in any reasonable format, standard loopholes are as forbidden as usual. 
**In the spirit of [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest answer in byte wins!**
Sandbox: <https://codegolf.meta.stackexchange.com/a/18142/59642>
  
[Answer]
# Scratch 3.0 39 blocks/323 bytes
[![Oh eval, I miss you](https://i.stack.imgur.com/kqsKa.png)](https://i.stack.imgur.com/kqsKa.png)
[Try it on~~line~~ scratch!](https://scratch.mit.edu/projects/333168394/)
*Alternatively, as SB syntax:*
```
when gf clicked
delete[all v]of[o v
ask()and wait
set[. v]to(answer
set[n v]to(1
repeat until<(n)contains[.
if<((n)mod(4))=(0
set[. v]to((. )*(n
else
if<((n)mod(4))=(1
change[. v]by(n
else
if<((n)mod(4))=(2
change[. v]by((0)-(n
else
set[. v]to((. )/(n
end
end
end
add(n)to[o v
change[n v]by(1
end
delete(length of(o))of[o v
```
Look at you guys, having fun with your fancy `eval` statements! Well, not me! **No**... Scratch doesn't have evals, so I had to do things the hard way... if statements.
At least it isn't `goto`s...
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), ~~251~~ ~~227~~ 202 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][T N
S T _Print_as_integer][S S S T  S T S N
_Push_10_newline][T N
S S _Print_as_character][S N
T   _Swap_top_two][S S S T  N
_Push_1][T  S S S _Add][S T S S T   N
_Copy_2nd_item][S T S S T   N
_Copy_2nd_item][S N
S _Duplicate_top][S S S T   S S N
_Push_4][T  S T T   _Modulo][S N
S _Duplicate_top][N
T   S S N
_If_0_Jump_to_Label_DIVIDE][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate_top][N
T   S T N
_If_0_Jump_to_Label_MULTIPLY][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S S N
_If_0_Jump_to_Label_ADD][S N
T   _Swap_top_two][S T  S S T   N
_Copy_2nd_item][T   S S T   _Subtract][N
S N
N
_Jump_to_LOOP][N
S S S N
_Create_Label_DIVIDE][S N
N
_Discard_top][T S T S _Divide][S T  S S T   S N
_Copy_3nd_item][S T S S T   S N
_Copy_3nd_item][T   S T T   _Modulo][N
T   S N
_If_0_Jump_to_Label_LOOP][N
N
N
_Exit_Program][N
S S T   N
_Create_Label_MULTIPLY][S N
N
_Discard_top][T S S N
_Multiply][N
S N
N
_Jump_to_Label_LOOP][N
S S S S N
_Create_Label_ADD][T    S S S _Add][N
S N
N
_Jump_to_Label_LOOP]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
[Try it online](https://tio.run/##RYxRCoAwDEO/k1P0CnojkYH@CQoev0vbTdeRbi9N3@N82n1te3M3M6p0QcRhAXXIg4rBpPFNDad8ZDaBHCCi8Z6jA@AHuaDgh4xk0YErWC3WSsgcQg1JRsjmQrqvSwc) (with raw spaces, tabs and new-lines only).
-24 bytes after a comment of *@JoKing* suggesting `n%i > 0`. Although only `if(x < 0)` and `if(x == 0)` are available in Whitespace, simply checking `if(x*-1 < 0)` is basically the same as `if(x > 0)`.  
An additional -25 bytes thanks to *@JoKing*.
**Explanation:**
Quote from the [Scratch answer](https://codegolf.stackexchange.com/a/193833/52210):
> 
> At least it isn't `goto`s...
> 
> 
> 
Did someone say `goto`? Whitespace has nothing else than `goto` to create both loops and if-statements. xD In addition it's a stack-based language, so I have to swap/discard/copy pretty often. And to top things off: Whitespace doesn't even have floating points and only integer-division, so I've used `n % i * -1 < 0` to exit the program if the integer cannot divide the current number.
*Pseudo-code:*
```
Integer n = STDIN as input
Integer i = 0
Label LOOP:
  Print n as number
  i = i + 1
  Integer t = i % 4
  If(t == 0):
    Jump to Label DIVIDE
  t = t - 1
  If(t == 0):
    Jump to Label MULTIPLY
  t = t - 1
  If(t == 0):
    Jump to Label ADD
  n = n - i
  Jump to Label LOOP
Label DIVIDE:
  n = n / i
  Integer m = n % i
  If(m == 0):
    Jump to Label LOOP
  Exit program
Label MULTIPLY:
  n = n * i
  Jump to Label LOOP
Label ADD:
  n = n + i
  Jump to Label LOOP
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~75 74~~ 73 bytes
*-1 byte thanks to Will Ness*
*-1 byte thanks to nimi*
```
(#1)
n#i|i`mod`4<1,n`mod`i>0=[n]|y<-i+1=n:(x!!i)n i#y
x=div:(*):(+):(-):x
```
[Try it online!](https://tio.run/##HcfRCoIwFIDh@z3FEW@2ptIigobrvovoAUxyuMpDehwZoeCzt8KLH76/scPz1rahMZfAYyUYxThj1fWu2uYqoUV4WJuCynnKU5TKkOZjFKEgwHhio3H40XwlNJf/UqHH0Fkk0BqOZ@CCLWfA9Qygs/50Be5fSO@sEcALlWW7EqSEYp9sVCnCt7639jGEtPb@Bw "Haskell – Try It Online")
Avoids the use of fractional ints to save on bytes
[Answer]
# [JavaScript (V8)](https://v8.dev/), 52 bytes
Prints groups of 4 terms. Inspired by [GB's Ruby answer](https://codegolf.stackexchange.com/a/193828/58563).
```
n=>{for(k=0;n%1==0;n/=k+=3)print(n,n*=++k,n-~k,--n)}
```
[Try it online!](https://tio.run/##NY/dDoIwDIXvfYpeaAKyBfYDQkx9Fo2RREmqQeINwVfHrptJu26nX7ezx@VzeV/H@2vSn3btcSU8zf1zzAasjrQzGEqJQ4Euf413mjJStMeiGBTp76C0pnxZp9t7AgQCPMEMkTvzCbYzLef8CH1GvMYGb5bNJoxkYHIoSzAqhFNQ/aNRoE1irDBWhfBMJtmJ7GSu5maSvcheUL7FJbkWuRb0EO@RveHiE9MI08hcy90kdyJ3KkTAW3Fi2KVhsIuUjT@x3JdkU7aKxjhdkLxYtfy647TN@gM "JavaScript (V8) – Try It Online")
---
# [JavaScript (V8)](https://v8.dev/), 54 bytes
Prints the terms of the sequence.
```
n=>{for(k=0;n%1==0;n=eval(n+'*+-/'[k++&3]+k))print(n)}
```
[Try it online!](https://tio.run/##NY/bioMwEEDf@xXz0G5NE9FcdBWJP7IsVIpC65ItKr6I3@5OJlmYIcmZM8nk1a3d/Jie7yVdq2Owh7PtNvxOyWjzxl2k9Yvt1@4ncfx642l2/Ro5/9DffGTsPT3dkji2H0s/L2DBgW1hg8DveILz5vY7a2BArYkF3Oynk29JQDLIMpDChxaQ/0cpIJXRUeQo4cOgGbEmrKmvwGLEhrAhFW/REReEC1I/wz20l7iY6JTklNRXYTXimnAtfHi9okkkTilRrIOlwk8U1ilxKJWHwTC1R4ZGVfi6xlTl8Qc "JavaScript (V8) – Try It Online")
---
# JavaScript (ES6), ~~59~~ 58 bytes
Returns an array.
```
f=(n,k)=>k&&(n=eval(n+'/*+-'[k&3]+k))%1?[]:[n,...f(n,-~k)]
```
[Try it online!](https://tio.run/##XdBLDoIwEADQvafoRmilfPoBwQQ9CGFBEIyWFCOGpVfHaaubJjNp07yZdvro1m7pX/fnO9bzddi2scaaKlKfVRBgXQ9rN2EdhekhisNGBaKNFCF7dmnaU6NpkiQj@PijSLv1s17maUim@YZHjBghKE0RoyYERdk/CopitvM0d5pTExJqfCAcELZXDswH0gFpy@EO4YPcgdyWH90tds9gkb4unC5srxKcDyoHKmrCtCjt2xlMyKCk8jz//QcHaRPG4JkbBVKYI2mH4/A2AcmL7Qs "JavaScript (Node.js) – Try It Online")
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~18~~ 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
[N"/*+-"Nè.VÐïÊ#=
```
[Try it online](https://tio.run/##MzBNTDJM/f8/2k9JX0tbV8nv8Aq9sMMTDq8/3KVs@/@/kSEA) or [verify all test cases](https://tio.run/##MzBNTDJM/V9W@T/aT0lfS1tXye/wCr2wwxMOrz/cpWz7v/bQNvv/0YY6RjrGOiY6pjpmOpY6RoaxAA).
**Explanation:**
```
[                # Start an infinite loop:
 N               #  Push the 0-based loop-index
  "/*+-"         #  Push string "/*+-"
        Nè       #  Index into this string with the loop-index
          .V     #  And use a 05AB1E-eval to calculate the next number
 Ð               #  Triplicate this number
  ï              #  Cast it to an integer
   Ê             #  And if it's NOT equal to the number we triplicated:
    #            #   Stop the infinite loop
  =              #  Print the number without popping
```
I'm using the legacy version of 05AB1E here, and also first calculate the next number before printing it, because the loop is 0-based and it will do a `/0` in the very first iteration. This saved a byte in comparison to the previous `N>` and `"*+-/"`. This only works, because in the legacy version a number that's being divided by 0 remains the same; whereas in the new version it would become 0; and in actual math it would give a division by zero error.
[Answer]
# [Piet](http://www.dangermouse.net/esoteric/piet.html), 297 190 144 codels (432 bytes)
[![New Piet Code](https://i.stack.imgur.com/CxFAZ.png)](https://i.stack.imgur.com/CxFAZ.png)
Tried a new approach using a `pointer` command as switch(k mod 4) to unify the output code, resulting in a denser 10x19 code picture. Then I golfed that down by 1 row and 2 collumns to 8x18.
Here is a trace, to see how it works:
[![enter image description here](https://i.stack.imgur.com/Bmpg0.png)](https://i.stack.imgur.com/Bmpg0.png)
The first line pushes a 0 on the stack as starting index (since we can only `push` natural numbers, we push 2 ones and then substract), then reads the input as number.
The leftmost collumn has the shared code of duplicating the number and popping one into output, then moving the index on top of the stack, incrementing it and then duplicating it thrice. We then enter the pastel red r-shaped block through the dark cyan codel for a `pointer` command which gives us different paths for the remainder of our index mod 4.
Mod 1, we exit through the top to multiply. We first shuffle a copy of our index down for later, then perform the multiplication. After passing through the white for a noop, we enter the collumn above to fix the cc parity (it needs to be flipped an even number of times to keep the loop stable), followed by a `pointer (1)` from entering the magenta bar: It acts as a catch for our four paths and send us back into the loop.
Mod 2, we exit backwards to sum. The shape of the pastel code block means we exit a row above from where we entered, and we use the 3 we push onto the stack by exiting through the red codel to `pointer (3)` ourselves upwards. This collumns has the white space before the arithmetic and a slightly different order of pushing and switching cc, because otherwise we would have colour overlap with integer-valued codels in the neighbouring collumn.
Mod 3 send us downwards for subtraction. Same deal as multiplication, except we cross over the division path on the way up (As the cc has differing parity when entering the pastel green bar, the two executions exit that bar at different ends). While doing so, we pick up an unwanted `duplicate` command, so we `pop` it back off with the dark green codel before entering the cc correction and collection bar.
Mod 4, we go straight ahead to divide. Here, we first have to re-shuffle the stack more severely to get two pairs of n and a to perform operations on, because we need to test if it's integer. We do that my doing `mod` on the first pair, then `not` on the result, then use that for a `pointer` - if it's not divisible, we keep going straight, which sends us with two `pointer` commands into the opposite corner into the inescapable block and thus ends program. Otherwise, we turn right and get a `divide` command from entering the magenta bar.
### Old Version
[![Piet Code](https://i.stack.imgur.com/6E4D1.png)](https://i.stack.imgur.com/6E4D1.png)
Very straightforward code: Pushes a 1 and the input on the stack, then loops through the four operations by: Shuffling the index on top of the stack, incrementing it by 1, duplicating it, shuffling one copy back down, performing the arithmetic operation, duplicating the number and popping one into output.
For division, which is the only one where the sequence can end, it creates a more complicated stack to first check if n mod index == 0, otherwise it enters the inescapable codel and terminates. Otherwise, it uses its second copy of i and n to perform the division.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 44 bytes
```
{$_,{($_,<* + - />[$++%4]~++$).EVAL}...^*%1}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv1olXqdaA0jYaCloK@gq6NtFq2hrq5rE1mlrq2jquYY5@tTq6enFaaka1v4vTqxUSNMw1LT@DwA "Perl 6 – Try It Online")
Anonymous code block that takes a number and returns a sequence. If we could skip the first element (which is always the same as the second element anyway), we could save 3 bytes by removing the `$_,`
[Answer]
# [Python 3](https://docs.python.org/3/), 60 bytes
```
f=lambda n,i=1:[]if n%1else[n]+f([n/i,n*i,n+i,n-i][i%4],i+1)
```
[Try it online!](https://tio.run/##DcNBCsIwEAXQvaeYTSExXyRtFSz0JCGLih38UKelduPpYx687Xe8V@tK0XGZPs/XJAaOcUiZKtbEefnOyXJQl@xK2LkO9YU5sekzGKIvuu5CoUlEiw49brjjgTYOJ6m2nXY4dfS@/AE "Python 3 – Try It Online")
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~72~~, ~~70~~, 69 bytes
```
n=>{for(int i=1;n%1==0;n=new[]{n/i,n*i,n+i,n-i}[i++%4])Write(n+" ");}
```
[Try it online!](https://tio.run/##bZDNasMwEITveYrFELBrGVs/dmMUBXrvvYeQQzE2CMIaEkMPIc/uTNf0pMIOEuKbkUbDvRrucf0YljjzcbrO38uJJgorh9Njmm955IVi0J73OoTGc@Dx53x5cB0Vv0ElVMXnOZbl3l2Kr1tcxpzLjLLCP1e/m3JdeKprrQhjFTV/0ymq9E4Mn5HHPIMDuBHcKMI4mFLCCmElrQWXEk4IJwG4xqZEK0QrAe/bRbLXWFyKd4J3knYAmBK9EL2ifgs5SAGNnhqe/p@e278YsCKUMc1WCLK/R04qGrzPQqZbXw "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~56 54~~ 52 bytes
```
f=->n,z=1{n%1>0?[]:[n,n*=z,n-~z,n-=1]+f[n/=z+3,z+4]}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y5Pp8rWsDpP1dDOwD461io6TydPy7ZKJ0@3DkTYGsZqp0Xn6dtWaRvrVGmbxNb@jzbUMdIx1jHRMdUx07HUMTKM1ctNLKiuqagpUEiLrtAryY9PAwtpqFkB2Zmatf8B "Ruby – Try It Online")
After some (failed) attempt with `eval`, I found out that the happiest solution is building the array with 4 elements at once, at least in ruby.
Thanks to Arnauld for -2 bytes.
[Answer]
# [R](https://www.r-project.org/), ~~[90 bytes](https://tio.run/##HYpLCoAgFEXX0kDQumIPLYtoJRGY0jTC5m/rlg3PJ5cSOKz5vJe4yicdl1SaVJukYwfCwBZJEma2ykzKuK4SwaL/yghN0H@H9p/3dVri1kQhaC@DLS8), ~~[87 bytes](https://tio.run/##FcjBDkAwDADQb3GQtHSZKrZl8SUiYYurCPf9enF871bdyjbfxxXTDE/eT0DD2GSQvgzkaeiKEFMoglb6NgN/Evp3IsNk/glk3PcOrceYlirVNa86ir4)~~ ~~[85 bytes](https://tio.run/##DcgxCoAwDADAtzgIiW0QEUFofYl0SGxRoTio4CC@PXY6uFOVp2vhA9BlTzkd6725Z9tzgopnKQWMoa47fHlagG30VD40YqMR09nkKVKhBTE94ud4Jgk6Dqo/ "R – Try It Online")~~ ~~[80 bytes](http://[Try%20it%20online!](https://tio.run/##K/r/P9G2ODkxT0PTujwjMydVQzExOslGNyc1L70kQyNRM1ZV1VCzOtE2WSNRJ8VGFygZq5Wkk6KdpG2ok2qjm6ILpPQ1krSNNTVrrROjdZNi/1uY/v8PAA%20%22R%20%E2%80%93%20Try%20It%20Online%22))~~ 74~~ [73 bytes](https://tio.run/##K/r/P9G2ODkxT0PTujwjMydVQzExOiRWVdVQM9E2WSNRJ8VGFySgFaKToh2ibaiTaqOboguk9DU0Qmx0Q7RNNHUNNTWtE6N1Q2L/W5j@/w8A)
A plain implementation of the rules:
```
a=scan();while(T<13)a=c(a,d<-a[T]*T,d+T+1,e<-d-1,e/((T<-T+4)-1));a[!a%%1]
```
[Try it online!](https://tio.run/##K/r/P9G2ODkxT0PTujwjMydVQzExOiRWVdVQM9E2WSNRJ8VGFySgFaKToh2ibaiTaqOboguk9DU0Qmx0Q7RNNHUNNTWtE6N1Q2L/W5j@/w8A "R – Try It Online")
with the `T<13` following from a deeper analysis of the puzzle. Indeed there are only three kinds of sequences: those of length 4, when a⁰ is not congruent to 1 modulo 8; those of length 
12 when a⁰ is congruent to 21 modulo 32; and those of length 8 for the remaining cases. 
An alternative code avoiding loops ends up being longer with 87 bytes: 
```
`~`=rep;b=(scan()-1)*c(32~4,8,40~3,1,9~3)/32+c(1,1,3,0~3,6,-c(8,1,9,-71,17)/8);b[!b%%1]
```
[Try it online!](https://tio.run/##FcjBDkAwDADQb3GQtHSZKrZl8SUiYYurCPf9enF871bdyjbfxxXTDE/eT0DD2GSQvgzkaeiKEFMoglb6NgN/Evp3IsNk/glk3PcOrceYlirVNa86ir4 "R – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~104~~ ~~86~~ 85 bytes
```
n#i=n:(cycle[(/),(*),(+),(-)]!!floor i)n i#(i+1)
takeWhile((==).ceiling<*>floor).(#1)
```
[Try it online!](https://tio.run/##HYoxD4IwEEZ3fsURHO5Aa@pGY92dHB0IQ4OnvVCLKcTEX18Jwxu@9z3v5pFDyDlWYqPB4TcE7vBIe6xXmpUD9WX5DNOUQCiCVCiNpsLbxY189xIY0VpSA0uQ@DrXly0mhZWm/HYSwRi43gCp2JaFx1QALMl9Oc0M@EkSF@UJOq1U26/fZmAHHk46/wE)
The `h=` can be omitted since it's only used for testing.
Ah, code golf, where a quadratic increase in time complexity is worth it for the reduction of one character.
# 104 bytes
```
f=flip
g x=scanl(f($))x.zipWith(f($))[1..].cycle$f<$>[(*),(+),(-),(/)]
takeWhile((==).ceiling<*>floor).g
```
[Try it online!](https://tio.run/##JY2xDsIgFEV3vuINDFAVUzeb0t3JsUPTgSAU0idtKDHVn8dahzOce4br1DIaxJyttOhnMsAqF60CMsso56v4@Ln1yf21K4XohX5rNNTWtOlYwY/ssHHaOPOeOJnUaFrn0TAmJRfaePRhqIvG4jRFLob8VD5AVcHtDoyT3SQ8JgKQonqZuBhgc/QhCcfhd3ntt7YvQMHBpcxf "Haskell – Try It Online")
I like this answer better, but alas it is longer.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~25~~ 24 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Another adaptation of [GB's Ruby solution](https://codegolf.stackexchange.com/a/193828/58974).
```
%1ª[UU*=°VU´ÒVU]cßU/=V±3
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=JTGqW1VVKj2wVlW00lZVXWPfVS89VrEz&input=MjE)
The main trick here is in the overloading of the `c` method for arrays. Pass it another array as an argument and it concatenates it to the original array. Pass it a number as an argument, as happens on the last recursive call, and it flattens the original array by that many levels - `1` in this case, after rounding. But, as the array is only ever one level deep, flattening it has no effect.
```
%1ª[UU*=°VU´ÒVU]cßU/=V±3     :Implicit input of integer U
%1                           :U modulo 1
  ª                          :Logical OR with
   [                         :Construct and array containing
    U                        :  U
     U*=                     :  U multiplied by
        °V                   :    V (initially 0) prefix incremented
          U´                 :  The new value of U, postfix decremented
            ÒV               :    Subtract the bitwise negation of V
              U              :  The now-decrmented U
               ]             :End array
                c            :Concatenate, or flatten by
                 ß           :  Recursive call to the programme with argument
                  U/=        :    U divided by
                     V±3     :      V incremented by 3
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 16 bytes
```
↑¦1G`I⁰zI¢ë*+-/N
```
[Try it online!](https://tio.run/##ASEA3v9odXNr///ihpHCpjFHYEnigbB6ScKiw6sqKy0vTv///zE "Husk – Try It Online")
## Explanation
```
↑¦1G`I⁰zI¢ë*+-/N   Input is a number n, accessible via ⁰.
          ë*+-/    Four-element list containing the functions *, +, - and /.
         ¢         Cycle infinitely.
       z       N   Zip with the list [1,2,3,4,5,..
        I          using the identity function (which works as function application since e.g. I+2 == (I+)2 == +2).
   G               Cumulative reduce from the left
    `I             using flipped identity function
      ⁰            with initial value n.
                   This results in [n, n*1, (n*1)+2, ((n*1)+2)-3, ..
↑                  Take the maximal prefix of elements
 ¦1                that are divisible by 1, or in other words are integers.
```
[Answer]
# Java 8, 84 bytes
```
n->{for(int i=1;n%1==0;n=new float[]{n/i,n*i,n+i,n-i}[i++%4])System.out.println(n);}
```
[Try it online.](https://tio.run/##bZA9T8MwEIb3/opTpUoOIYFAQYLI7Ax06RhlMK6DXNJLFF@KUJTfHi4fg1E7nKXnvt73fFRnFR0P34MulXPwoSx2KwCLZJpCaQO7EQHOlT2AFkVZKQIMUk72K34cKbIadoAgYcDorSuqRvA4WJmkuEmkvE9RovmBaTbLO7yzt3jDEXJEts9sGG62ebD/dWROcdVSXDe8oUTBQv2Qjjp1@1myziI3uTmxV7Enbv3KclDBbJSMI5FMBhd48OHRh60PTz48@/Dyb1tycfzkZirO32Oxbmmxc@Wo9ftYf4V1ODfOyzHWwucrg4twP/wB)
Creating an array with all four values is inspired by [*@GB*'s Ruby answer](https://codegolf.stackexchange.com/a/193828/52210), although I now notice that using a ternary if-statement is the same amount of bytes:
```
n->{for(int i=0;n%1==0;n=++i%4<1?n/i:i%4<2?n*i:i%4<3?n+i:n-i)System.out.println(n);}
```
[Try it online.](https://tio.run/##bZA9b4MwEIb3/IpTpEimCFqStFKhlLlDs2SsOrgOVJeSA@EjUhXx26mNGVwli32P7@N9z0d5ltHx8DOqWmoN7xLpsgBA4rKrpCphZxHg3OABlKjqRjJQkJnHYWEOzZJRwQ4Ichgper1UTSdMO2D@kNEqye2VhyGuti9JQfeY2mhd0J2LNgWFmFKEwf5Xc3mKm57jtjMTahJGaBgzq9P2X7XRmeUmNyfjVezZlH5/fIIMnFEuNYtkMjjD2oeND1sfHn148uH537TkavnJzZR034PU9jzbubHU8s3mU1iGrtANp1gJn280zsLD@Ac)
[Answer]
# [Perl 5](https://www.perl.org/), 53 bytes
```
@a=qw(/ * + -);say,eval"\$_$a[++$i%4]=$i"while$_==int
```
[Try it online!](https://tio.run/##NY5bCsIwEEX/s4pQIqhNH3m02pSCG3AFKiUfBQO1VluUbt44ExHOkHDnkJuxe/aFnzKTbrOsvi3M1f5gm8d7ndEtjWmyqSe78O5l@@jMWmZPcczcSl8a5qL31fUda5vGDbNHL4q8MFRwRHGa/yk5TQSRhkqOaBCIMqgABWREG0x1UBUpDKbA7ieHu4BDk9KgAuwhJJWhFUdwuQ@PC@gTsK@IhL9IyMNAkcx/ZTAKIx3qJXQoGFl@7uPs7sPkk37wybFIc/EF "Perl 5 – Try It Online")
[Answer]
# [Red](http://www.red-lang.org), 102 bytes
```
func[n][k: m: 0 until[foreach o[* + - /][print n t: n
n: do reduce[n o m: m + 1]]k: k + 1 t % m <> 0]]
```
[Try it online!](https://tio.run/##FYwxDoMwEAR7XrFNGlAUoDyhPCLt6QpknwUCzpFlv9@YbjWa2aS@/tSzdIFqKObYhA/CRRhRLO8nh5h0dRsi9xjwxkf4n3bLMGSCdUbwEUl9ccqG@LRXMyeRdnQ8CxmvxpYvRpEaME/1Bg "Red – Try It Online")
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 57 bytes
```
{n=$1;for(k=1;n%1==0;n/=k++)print n,n*=k++,n+=k++,n-=k++}
```
[Try it online!](https://tio.run/##SyzP/v@/Os9WxdA6Lb9II9vW0DpP1dDW1sA6T982W1tbs6AoM69EIU8nTwvE1cnThlC6IKr2/39DAA "AWK – Try It Online")
[Answer]
# [Rutger](https://github.com/cairdcoinheringaahing/Rutger), 310 bytes
```
n=e=$Input;
a=0;
w=While[{m=Modulo[$e];Not[m[1]];}];
w=w[{f=For[4];f=f[@x];f=f[{Print[$e];q=Equal[$x];i=If[{q[1];}];i=i[{k=Times[$e];}];Do[$i];i=If[{q[2];}];i=i[{k=Add[$e];}];Do[$i];i=If[{q[3];}];i=i[{k=Subtract[$e];}];Do[$i];i=If[{q[4];}];i=i[{k=Divide[$e];}];Do[$i];e=k[a=Increment[$a]];}];Do[$f];}];
Do[$w];
```
[Try it online!](https://tio.run/##dc/NCsIwDAfw@55jD6BztxJQmMIOiqDgIfRQXabBfbjaOmH47LNzoEPYqaH/XxKirTmTbtsCCPy4uFkjPAUT4dVwuHBG2OSwLhObleiTFJvSYI5TKcVLdqbGJoVVqTGUIoUU58/@bbaaC/NpqWBZWZWh7yKG2GWVG9D1MzA2V9hzTvcPdX@R28M/GAzhIklG2GzIdvZotDqZERsObcQPTuhPElxRQVycNOXUXaHkN077y7uylqJtg@kb "Rutger – Try It Online")
It's about time I used Rutger again. Unfortunately, it may not be the best language for the task, as it has no form of `eval`, forcing me to use four if statements
## How it works
### How Rutger works
A brief foreword on how the language works: Everything is either an assignment or a function, and every function takes exactly one argument. For operations that require more than one argument (e.g. multiplication), the first call returns a *partial function*, that, when called again with the second argument, returns the expected result. For example:
```
left = Times[5];
Print[left[6]];
```
will print out 30: [Try it online!](https://tio.run/##KyotSU8t@v8/JzWtRMFWISQzN7U42jTWmiugKDOvJBokHG0WG2v9/z8A "Rutger – Try It Online"). While usually this is longer than the usual alternative, it can at times save bytes, if a function is called repeatedly with one constant argument, and one changing argument, for instance when printing out times tables.
This one argument rule applies to everything that isn't a constant or a variable, including loops and conditionals. However, loops and conditionals (`For`, `Each`, `While`, `DoWhile`, `If` and `IfElse`) are *doable*, meaning that in order to actually run them, the `Do` function must be called (see the last line in the answer). Again, this can save bytes when repeatedly running the same loop, or allow you to run arbitrary code between the definition and running of loops.
Finally, there are three ways of referring to variables, all of which are used in this program. The first is *direct referencing*, where the variable name is prefixed with a `$` symbol. This accesses the value of the variable directly and returns it. The second is *functional referencing*, which doesn't have a prefixing character. This allows the code to distinguish between (potentially partial) functions assigned to variables, and actual variables containing a specific value. Finally, *indirect referencing*, prefixed with an `@` symbol, creates a variable (if it doesn't already exist) and returns the variable object within a given scope. This allows you to create a loop variable (e.g. `i` in `for i in range(...)`).
### How the actual solution works
Here is the ungolfed code:
```
n = elem = $Input;
var = 0;
while = While[{
	mod = Modulo[$elem];
	Not[mod[1]];
}];
while = while[{
for = For[4];
for = for[@index];
for = for[{
	Print[$elem];
	equal = Equal[$index];
	if = If[{ equal[1]; }];
	if = if[{ func = Times[$elem]; }];
	Do[$if];
	if = If[{ equal[2];}];
	if = if[{ func = Add[$elem];}];
	Do[$if];
	if = If[{ equal[3];}];
	if = if[{ func = Subtract[$elem];}];
	Do[$if];
	if=If[{ equal[4];}];
	if=if[{ func = Divide[$elem];}];
	Do[$if];
	elem = func[var = Increment[$var]];
	}];
	Do[$for];
}];
Do[$while];
```
[Try it online!](https://tio.run/##hZHBTsMwDIbPzVP00AdgME5RJZAGUg8gJJA4WDmUxoFIbQIh2ZAmnr3Ya7sNadUucezf/hzlDym@Y@h7l5c5tthRKCr3maIU6zpQdiHF5sO2SNdXjrAVWec1pQ9ep9ZDwWNKiuzRRyAFFoqyX3WY24xzxjPw3gdYkjpkdMKNdRp//pVoyVOwLh7o@JXqltQ7jlBMIyKzhqqVgW2@a6H1Muftg2BZMMk1dH@xHX5PxKFnRe@35iTnUsnTmFutJ8g5xtUc4zm9xVA3cR5UHmGWe0x5DFnZtdU4hxjd5F4YrKxcE7BD/lUqsEvZfog@fXSNs51jSvb94voP "Rutger – Try It Online")
As you can see, it starts by assigning the three variables `n`, `e` and `a`, which represent the input, the changing element in the sequence, and the modification number for each new element respectively. We then create a while loop:
```
w=While[{m=Modulo[$e];Not[m[1]];}];
```
The braces (`{` and `}`) define a *block* of code, where the final statement in the block is the condition for the while loop. In this case, we start by defining a partial modulo function, which will take in a second argument `m`, and return `e % m`. We then call this partial function with \$1\$ as its second argument, returning \$0\$ for integers and a non-zero integer for floats. We then calculate the logical not of this, mapping \$0 \to 1\$ and \$n \to 0, n \ne 0\$.
Next we come to the absolute monstrosity consisting of the while loop's body:
```
w=w[{f=For[4];f=f[@x];f=f[{Print[$e];q=Equal[$x];i=If[{q[1];}];i=i[{k=Times[$e];}];Do[$i];i=If[{q[2];}];i=i[{k=Add[$e];}];Do[$i];i=If[{q[3];}];i=i[{k=Subtract[$e];}];Do[$i];i=If[{q[4];}];i=i[{k=Divide[$e];}];Do[$i];e=k[a=Increment[$a]];}];Do[$f];}];
```
The primary part of this loop is a for loop, that iterates \$4\$ times each iteration of the while loop, has an iteration variable of `x` and consists of:
```
Print[$e];
q=Equal[$x];
i=If[{q[1];}];i=i[{k=Times[$e]    ;}];Do[$i];
i=If[{q[2];}];i=i[{k=Add[$e]      ;}];Do[$i];
i=If[{q[3];}];i=i[{k=Subtract[$e] ;}];Do[$i];
i=If[{q[4];}];i=i[{k=Divide[$e]   ;}];Do[$i];
e=k[a=Increment[$a]];
```
The first statement prints out each iteration of the sequence before modifying it. We then create a partial function to check equality with the loop variable `x`, and encounter four if statements. Each statement checks if `x` is equal to 1, 2, 3 or 4 respectively, and then assigns `k` to each function in `*`, `+`, `-` and `/`, then makes it into a partial function with `e` as its argument. Finally, we assign `e` to `k` run with `a` as its second argument, and increment `a`.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 52 bytes
```
->n{i=0.0;n=[p(n)/i+=1,n*i,n+i,n-i][i%4]until 0<n%1}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOtPWQM/AOs82ukAjT1M/U9vWUCdPK1MnTxuIdTNjozNVTWJL80oycxQMbPJUDWv/p0UbGcb@BwA "Ruby – Try It Online")
[Answer]
# dzaima/APL, ~~34~~ 33 bytes
```
⌽1↓{⍵,⍨⊃⍵(⍎⊃'÷×+-'⌽⍨≢⍵)≢⍵}⍣{⍵≢⌊⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pSszMTfz/qG@qp/@jtgkG/9OA5KOevYaP2iZXP@rdqvOod8WjrmYgS@NRbx@QpX54@@Hp2rrqQDUgqc5FQClNCFX7qHcxSA@I19MFEgCZCzQvTcGQC8YyMvwPAA "APL (dzaima/APL) – Try It Online")
-1 thanks to [ngn](https://codegolf.stackexchange.com/users/24908/ngn)
[Answer]
# TI BASIC, 68 Bytes
```
1→A
DelVar L1Prompt N
Repeat fPart(N
N→L1(A
NA-1→O
augment(L1,{NA,Ans+A+2,Ans→L1
O/(A+3→N
A+4→A
End
L1
```
We set up a counter in A and clear L1 so we can use it to track the sequence. We then repeat until the division step causes a fraction. Inside the loop we first store N to the list. Storing to one element past the end of a list or an empty list creates that element, so this one store both adds the result of the division when it doesn't cause a fraction, and initializes the list during the first pass. We then use augment to append the next 3 terms of the sequence. The math works out a few bytes smaller by calculating term A4k+3 in variable O and then basing A4k+2 and A4k+4 off O. Then we do the division separately to reset N for the repeat check and add 4 to A.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 29 bytes
```
ＮθＷ¬﹪θ¹«Ｉθ⸿≔§⟦∕θⅉ×θⅉ⁺θⅉ⁻θⅉ⟧ⅉθ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05qrPCMzJ1VBwy@/RMM3P6U0J1@jUEfBUFNTU6GaizOgKDOvRMM5sbgEqBaoGCqgFFOkBOI5FhdnpudpOJZ45qWkVmhEu2SWZaakggyI1NDU1FEIycxNLUZwA3JKkXi@mXkIbixMFOSk2v//jQz/65blAAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｎθ
```
Input the initial value.
```
Ｗ¬﹪θ¹«
```
Repeat until the value is no longer an integer.
```
Ｉθ⸿
```
Print the value on its own line.
```
≔§⟦∕θⅉ×θⅉ⁺θⅉ⁻θⅉ⟧ⅉθ
```
Calculate the four available arithmetic operations and select the correct one depending on the current output line number.
[Answer]
# [C (clang)](http://clang.llvm.org/), 80 bytes
```
i;f(n){for(i=0;~i;n=++i%4?i%4-1?i%4-2?n-i:n+i:n*i:n%i?i=-1:n/i)printf("%d ",n);}
```
[Try it online!](https://tio.run/##ZY1NboMwEIX3c4oRFZJdSottMCEuzUW6iSC0I6WTiMAqSq9OB5au7WfN@@avy7vzkb@WhcKgWN@Hy6ioLcIvBW6zjNLyIMrN9tsD57TnTPQsSulAbW72/Eb6OhJPg0rSHpMX1uGxPBF357k/4ftt6uny@v0BIDX4cyRWGu8wKKPDdZ5uKvnkRAcBNgYuBmUMqhj4GDT/tkR7AeWMp2keGYsAj8WgQYfFdj3mBgEsWixxjZykKnEApRAvDqASUm/5Co2RAMBLaicWoMFmhTvpMQUaL1bmGVyfQ1us0yp04koZZmt0NVovNX8 "C (clang) – Try It Online")
```
A golfed switch statement.   
```
Thanks to many @ceilingcat improvements.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~78~~ 76 bytes
```
f=lambda n:n[-1]%1and n[:-1]or f(n+[eval(f"n[-1]{'/*+-'[len(n)%4]}len(n)")])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P802JzE3KSVRIc8qL1rXMFbVMDEvRSEv2grIzi9SSNPI045OLUvM0UhTAstXq@traeuqR@ek5mnkaaqaxNZCWEqasZr/C4oy80o00jSiDWM1NbngPCMUnjEKzwSFZ4rCM0PhWaKaCbLiPwA "Python 3 – Try It Online")
Takes input as a list of 1 item and recursively appends the next item of the sequence until it's a non-integer.
In the case that taking input as a list is not allowed, here is a very quickly patched version which takes input as an int.
# Input as an integer, 102 bytes
```
f=lambda n:type(n)==int and f([n])or n[-1]%1and n[:-1]or f(n+[eval(f"n[-1]{'/*+-'[len(n)%4]}len(n)")])
```
[Try it online!](https://tio.run/##TcxBCsIwEIXhvacIhdIZS5HYVrCQk4QsIk1QiNNQglDEs8eoCLP7eA/@uKXrQn3OXgV7v8xW0JS26IBQqRslYWkWHjQZXFZBupOmlp@N9FRcNg/UavewAXz1/Z/NYd92jQ6OSqUezOunCg3muJYoeJCIu7@PzD3zwDwyn5jPvFOi@Q0 "Python 3 – Try It Online")
+2 bytes thanks to me forgetting to name the recursive function...  
-4 bytes thanks to Jitse
[Answer]
# [Twig](https://twig.symfony.com/), 164 bytes
Okay, this was actually horribly horrible to write.
Limitations:
* No `returns`! You either output or don't output
* No `while` loops. You **must** use recursion or nothing
* No easy way to output! You have to repeat the output everytime
* You can't give variables a value without using the `set` tag
* No easy way to get out of a loop. There's no `break`, `continue`, `goto` or similar. This makes a loop impossible to use.
* There is only 1 loop: `for ... in ....`, and it loops over all the elements in an array, with no way to stop.
All those made the code massive!  
Hey, I even made it longer than the Java answer!  
It's as long as [@Arnauld's](https://codegolf.stackexchange.com/users/58563/arnauld) [JavaScript answer](https://codegolf.stackexchange.com/a/193826/)! ... With all 3 alternatives combined.
**Here's the code:**
```
{%macro a(b,n=1)%}{{n<2?b}}{%set b=b*n%},{{b}}{%set b=b+n+1%},{{b}}{%set b=b-(n+2)%},{{b}}{%set b=b/(n+3)%}{%if(b//1)==b%},{{b~_self.a(b,n+4)}}{%endif%}{%endmacro%}
```
You can try it on <https://twigfiddle.com/zw5zls>
---
## How to use:
Simply import the file and call the first macro.
```
{% import 'file.twig' as a %}
{{ a.a(21) }} {# 21,21,23,20,5,25,31,24,3,27,37,26 #}
```
To have an usable array, you can do `a.a(21)|split(',')`.
---
## Ungolfed:
```
{% macro calc(number, index = 1) %}
    {% if index < 2 %}
        {{ number }}
    {% endif %}
    
    {% set number = number * index %},{{ number }}
    {% set number = number + index + 1 %},{{ number }}
    {% set number = number - (index + 2) %},{{ number }}
    {% set number = number / (index + 3) %}
    
    {#
        verifies if it is an integer.
        this is done with an integer division with 1 and compare with itself
        if both values are the same, the number is an integer
        otherwise, it is a floating-point number
    #}
    {% if (number // 1) == number %}
        ,{{ number ~ _self.calc(number, index + 4) }}
    {% endif %}
{% endmacro %}
```
Should be easy to read.  
This ungolfed answer will NOT give the correct output, as it will throw random whitespaces.  
It exists merely to be humanly readable.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
×+_÷4ƭ‘ɼ$ḞƑÐ¿Ṗ
```
A full program\* that accepts an integer and prints the resulting sequence.
**[Try it online!](https://tio.run/##AScA2P9qZWxsef//w5crX8O3NMat4oCYybwk4biexpHDkMK/4bmW////MjE "Jelly – Try It Online")**
### How?
```
×+_÷4ƭ‘ɼ$ḞƑÐ¿Ṗ - Main Link: integer, n
           Ð¿  - collect while X, initially n, is:
          Ƒ    - ...invariant under
         Ḟ     -     floor to the nearest integer
        $      - ...last two links as a monad - f(X):
       ɼ       -   apply to the register (initially zero) and yield:
      ‘        -     increment (i.e. get the next right operand)
    4ƭ         -   calling these four links in turn:
×              -     multiply
 +             -     add
  _            -     subtract
   ÷           -     divide
             Ṗ - pop off the trailing, non-integer
               - implicit print
```
\* Note: this is not a reusable Link since the tie quick, `ƭ`, does not reset between calls to a Link.
]