[Question]
  [
Given a strictly positive integer **n**, follow these steps:
1. Create an array **A** with **n** **1**s.
2. If **A** only has one element, terminate. Otherwise, starting from the first element, replace each pair of **A** with its sum, leaving the last element as is if **A**'s length is odd, and repeat this step.
The output should contain **A**'s state after each step in order from the first step to the last. Usage of [standard loopholes](https://codegolf.meta.stackexchange.com/q/1061/41024) is forbidden. This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge, so the solution with the fewest bytes in each language wins.
## Test cases
Each line in the output of these examples is a state. You can output via any reasonable format.
Input: `1`
```
[1]
```
Input: `4`
```
[1, 1, 1, 1]
[2, 2]
[4]
```
Input: `13`
```
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[2, 2, 2, 2, 2, 2, 1]
[4, 4, 4, 1]
[8, 5]
[13]
```
Input: `15`
```
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[2, 2, 2, 2, 2, 2, 2, 1]
[4, 4, 4, 3]
[8, 7]
[15]
```
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
Å1Δ=2ôO
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cKvhuSm2Roe3@P//b2gKAA "05AB1E – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 10 bytes
```
:g`t2estnq
```
[Try it online!](https://tio.run/##y00syfn/3yo9ocQotbgkr/D/f0NjAA "MATL – Try It Online\"t Online\"")
### How it works
```
:     % Input n (implicit). Range [1 2 ... n]
g     % Convert to logical. Gives [1 1 ... 1]
`     % Do...while
  t   %   Duplicate
  2   %   Push 2
  e   %   Reshape as 2-column matrix, in column-major order, padding with 0 if needed
  s   %   Sum of each column
  t   %   Duplicate
  n   %   Number of elements
  q   %   Subtract 1. This will be used as loop condition
      % End (implicit). If top of the stack is not zero run new iteration
      % Display stack, bottom to top (implicit)
```
[Answer]
# [Python 3](https://docs.python.org/3/), 57 bytes
```
def f(i,j=1):print(i//j*[j]+[i%j][:i%j]);i>j and f(i,j*2)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNI1Mny9ZQ06qgKDOvRCNTXz9LKzorVjs6UzUrNtoKRGpaZ9plKSTmpUAUaxlp/k/TMNTkStMwARGGxmDSVPM/AA "Python 3 – Try It Online")
# [Python 2](https://docs.python.org/2/), 51 bytes
```
def f(i,j=1):print i/j*[j]+[i%j][:i%j];i>j>f(i,j*2)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/PyU1TSFNI1Mny9ZQ06qgKDOvRCFTP0srOitWOzpTNSs22gpEWmfaZdmBlWkZaf5P0zDU5ErTMAERhsZg0lTzPwA "Python 2 – Try It Online")
*-6 bytes total thanks to tsh*
Recursive function. For each step, it constructs a list of powers of `2`, such that the sum is smaller than or equal to the given integer. It then appends the remainder, if it is larger than `0`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
L€+2/Ƭ
```
**[Try it online!](https://tio.run/##y0rNyan8/9/nUdMabSP9Y2v@//9vaAoA "Jelly – Try It Online")**
[Answer]
# JavaScript, 55 bytes
```
f=(n,t=1,r=n)=>r>t?t+[,f(n,t,r-t)]:n>t?r+`
`+f(n,t+t):r
```
[Try it online!](https://tio.run/##NchLCoAgEADQvSdx0BZFtAisg0RglIJFk4xD0OntAy3fW6dzSjOFyEWKYXG0H7i5K2dvJGo2pSaDYDrquGc1aP@upoJhbPE5UlZY9a1iaClHCsjSy7oCED/KBiDf "JavaScript (SpiderMonkey) – Try It Online")
This is basically the golfed version of following codes:
```
function f(n) {
  var output = '';
  t = 1;
  for (t = 1; ; t *= 2) {
    for (r = n; r > t; r -= t) {
      output += t + ',';
    }
    output += r;
    if (n <= t) break;
    output += '\n';
  }
  return output;
}
```
[Answer]
# [R](https://www.r-project.org/), 65 bytes
-1 byte thanks to Giuseppe.
```
n=scan();while(T<2*n){cat(rep(+T,n%/%T),if(n%%T)n%%T,"\n");T=2*T}
```
[Try it online!](https://tio.run/##K/r/P8@2ODkxT0PTujwjMydVI8TGSCtPszo5sUSjKLVAQztEJ09VXzVEUyczTSNPFcgAETpKMXlKmtYhtkZaIbX/DU3/AwA "R – Try It Online")
Avoids recursion. In R, `%/%` is integer division and `%%` is the modulo. For each power of 2 `k=2^i`, we need to print `n%/%k` times the value `k`, and then `n%%k` if that value is non zero. Do this for all powers of 2 smaller than \$2n-1\$.
Here I am using `T` instead of `k`, since it is initialized as `TRUE` which is converted to 1. I still need to print `+T` instead of `T` to avoid a vector of `TRUE`s in the output.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
.u+McN2m1
```
[Try it online!](https://tio.run/##K6gsyfj/X69U2zfZz0gr1vD/f0NjAA "Pyth – Try It Online")
```
.u          # Apply until a result is repeated, return all intermediate steps: lambda N,Y:
  +M        # map by + (reduce list on +):
    cN2     # chop N (current value) into chunks of 2, last one is shorter if needed
       m1Q  # map(1, range(Q)) (implicit Q = input)
```
-1 byte thanks to FryAmTheEggman
[Answer]
# [JavaScript (V8)](https://v8.dev/), 109 bytes
```
f=n=>g(Array(n).fill(1));g=(a,i=1)=>{console.log(a);if(a[i]){for(;a[i];)a.splice(i-1,2,a[i-1]+a[i++]);g(a);}}
```
[Try it online!](https://tio.run/##FYzBCsMgEETv/RF3iQnYU4sYyHcED1sbZYvEoCVQQr7dmsNjhgczH9qpuMzbt98ftXqzmjHAlDP9YMXBc4ygEHUwQJKNQjMeLq0lxWWIKQChZg80s8XDpwz6qhppKFtktwD3St5lk72yXYuus@3smp1n9fBEfQswCxJSvBqu8W4swmL9Aw "JavaScript (V8) – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~55~~ 54 bytes
```
Last@Reap[1~Table~#//.a_:>Tr/@Sow@a~Partition~UpTo@2]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73yexuMQhKDWxINqwLiQxKSe1TllfXy8x3soupEjfITi/3CGxLiCxqCSzJDM/ry60ICTfwShW7X9AUWZeSbSyrl2ag3Ksmr5DNZehDpeJDpehMRCbctX@BwA "Wolfram Language (Mathematica) – Try It Online")
~~Finally, `Sow`/`Reap` beats an alternative!~~
Returns a singleton list containing a list of the steps.
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), ~~15~~ 17 bytes
```
{{+/'0N 2#x}\x#1}
```
[Try it online!](https://tio.run/##y9bNz/7/P82qulpbX93AT8FIuaI2pkLZsPZ/moKh8X8A "K (oK) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), ~~20~~ 17 bytes
```
_2+/\&.>^:a:<@#&1
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/44209WPU9OzirBKtbByU1Qz/a3JxpSZn5CukKZhAGOrqMAFDYwwR0/8A "J – Try It Online")
*-5 bytes thanks to Bubbler*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
-1 byte thanks to [Erik the Outgolfer](https://codegolf.stackexchange.com/users/41024/erik-the-outgolfer).
```
1x+2/Ƭ
```
[Try it online!](https://tio.run/##y0rNyan8/9@wQttI/9ia/0CWKQA "Jelly – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), 13 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
_ò mx}hUõÎü)â
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=X/IgbXh9aFX1zvwp4g&input=MTU)
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 17 bytes
```
;1j₍ẹẉ₂{ġ₂+ᵐ}ⁱ.ẉȮ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6kUFCUn1KanFpspfRwV6f9o7YNj5qaHnUsf7hjG5Bf@3DrhP/WhlmPmnof7toJFABKVh9ZCCS1gTK1jxo36gEFT6z7/z/aUMdEx9BYx9A0FgA "Brachylog – Try It Online")
As horribly long as this is, I still feel a bit clever for using `.ẉȮ`: the obvious way to print something, then check if its length is 1 would be `ẉ₂l1`, `ẉ₂~g`, or `ẉ₂≡Ȯ`, where the `≡` in the last one is necessary because `ẉ₂` unifies its input and output *before* it prints them, and `Ȯ` is pre-constrained to be a list of length 1, so the unification fails if the input is not a list of length 1. At the end of a predicate, this feature of `ẉ₂` can be circumvented, however, by using the output variable instead of subscripting `ẉ`: `.ẉȮ` first unifies its input with the output variable, then prints the output variable, and only afterwards unifies the output variable with `Ȯ`.
[Answer]
# [Haskell](https://www.haskell.org/), 75 bytes
```
g.pure
g x|x!!0<2=[x]|1>0=(g$(\z->filter(0/=)[-div(-z)2,div z 2])=<<x)++[x]
```
[Try it online!](https://tio.run/##DcyxDoMgFEDRvV/xTBwglhZJuvH8EXUgFigpGoK2IcRvL2W7y7kvtb@198UAwlTsLXyivlhIZ2oaLgWOaT77gSOxLZkyG4zzh46E35GO7Om@hGUqrjUgg5gpSplo11VVVuW2Og3RbQe0YKB/lN9ivLJ7YUsIfw "Haskell – Try It Online")
Works backwards from the list `[n]` until it reaches a list of just ones.
Going forwards, I could get 80 bytes using `chunksof` from `Data.List.Split`:
```
import Data.List.Split
f x=g$1<$[1..x]
g[n]=[[n]]
g x=x:(g$map sum$chunksOf 2 x)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzyezuEQvuCAns4QrTaHCNl3F0EYl2lBPryKWKz06L9Y2GkgAmUCpCiuNdJXcxAKF4tJcleSM0rzsYv80BSOFCs3/uYmZeQq2CgVFmXklCioKaQqGpv8B "Haskell – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Çë⌐ⁿ┤5π»Å╡
```
[Run and debug it](https://staxlang.xyz/#p=8089a9fcb435e3af8fb5&i=1%0A4%0A13%0A15&a=1&m=2)
## Procedure:
1. Generate 0-based range.
2. Repeatedly halve each element until all items are zero.
3. Calculate run-lengths for each unique array.
## Annotated Source:
```
r       main:[0 .. 5] 
{{hmgu  main:[[0 .. 5], [0, 0, 1, 1, 2, 2], [0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0]] 
m:GJ    main:"1 1 1 1 1 1" 
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 19 bytes
```
ＮθＩＥ↨⊖⊗θ²Ｅ⪪Ｅθ¹Ｘ²κＬλ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05oroCgzr0TDObG4RMM3sUDDKbE4VcMlNbkoNTc1ryQ1RcMlvzQpB0gXamrqKBgBMUhVcEFOJkR9oY6CIVAwIL8caJ6RjkI2SJlPal56SYZGjiYYWP//b2j8X7csBwA "Charcoal – Try It Online") Link is to verbose version of code. Uses Charcoal's default output format, which is one number per line, with subarrays double-spaced from each other. Explanation:
```
Ｎθ                  Input `n` into a variable
       θ            `n`
      ⊗             Doubled
     ⊖              Decremented
    ↨   ²           Converted to base 2 (i.e. ceil(log2(input)))
   Ｅ                Map
           Ｅθ¹      List of `1`s of length `n`
          ⪪         Split into sublists of length
               ²    Literal `2`
              Ｘ     To power
                κ   Loop index
         Ｅ          Map over each sublist
                 Ｌλ Take the length
  Ｉ                 Cast to string for implicit print
```
[Answer]
# [Perl 5](https://www.perl.org/), 46 bytes
```
say$_="1 "x<>;say while s/(\d+) (\d+)/$1+$2/ge
```
[Try it online!](https://tio.run/##K0gtyjH9/784sVIl3lbJUEGpwsbOGshTKM/IzElVKNbXiEnR1lQAk/oqhtoqRvrpqf//G5r@yy8oyczPK/6v62uqZ2BoAAA "Perl 5 – Try It Online")
Output is space separated.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 38 bytes
```
{1 xx$_,*.rotor(2,:partial)>>.sum...1}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/2lChokIlXkdLryi/JL9Iw0jHqiCxqCQzMUfTzk6vuDRXT0/PsPZ/cWKlQpqGiaY1F4RlqvkfAA "Perl 6 – Try It Online")
There's some shortcut to partial rotoring that I'm not remembering right now...
### Explanation:
```
{                                    }  # Anonymous code block
                                 ...    # Return a sequence
 1 xx$_,            # Starting with a list of 1s with input length
        *           # Where each element is
         .rotor(2,:partial)        # The previous list split into chunks of 2 or less
                           >>.sum  # And each chunk summed
                                    1  # Until the list is length 1
```
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), 30 bytes
```
(|1){!1>|^(:. ,")^
,(!2/|+")}.
```
[Try it online!](https://tio.run/##y05N//9fo8ZQs1rR0K4mTsNKT0FHSTOOS0dD0Ui/RltJs1bv/39DUwA "Keg – Try It Online")
I've actually been meaning to complete this challenge for a while (I mean, I emailed myself the link to it so I would remember), but I've never gotten around to doing so until now!
[Answer]
# APL, 28 chars
```
{1≢≢⎕←⍵:∇+/(⌈.5×≢⍵)2⍴⍵,0}⍴∘1
```
vector of 1s
```
⍴∘1
```
output the argument and check if length is different than 1: if so, go on
```
1≢≢⎕←⍵:
```
get half of the length and round up
```
⌈.5×≢⍵
```
reshape into a nx2 matrix adding a trailing 0 if needed
```
(⌈.5×≢⍵)2⍴⍵,0
```
sum of row by row
```
+/
```
recurse
```
∇
```
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 24 bytes
A horribly long answer... golfed out 1 byte by using a hard-to-read output format
```
~[1]*{..2/{{+}*}%\,(}do;
```
[Try it online!](https://tio.run/##HcyxCsIwFIXhPU9xoAhSS4o6ugsuOjpohxBjE6xJSG8tEuKrx@hZ/4/Tu@E@ymA85fy5rLs6cr5pY1ylOi2uzTLd3C5XOLoGB4gnrCNQeBvbgxykVoKgVVCcc9ahwjkID9IKIwn5gLFFCQxmJBYZyjyKOk3kJ8JsSJdq1TwYq1hqf23vghJSw71U@D8ZW2zefgE "GolfScript – Try It Online")
## Explanation
```
~                        // Dump the contents of the input string
 [1]*                    // Create a 1-list with the length of the input string
     {              }do  // do ... while
                 \,(     // the length of the array is larger than 1
      .                  // Extra evolution step that we need to keep
       .                 // Create a copy of the input
        2/               // That splits into parts of 2 items
          {    }%        // For each over the splitted array:
           {+}*          // Reduce the item with addition
                         // e.g. [1] -> [1], [1 2] -> [3], etc.
                       ; // Discard the abundant copy
```
[Answer]
# [V (vim)](https://github.com/DJMcMayhem/V), 93 bytes
```
:s/1\n/a
D@"i1 <esc>
qqYplllA]<esc>0i[<esc>:s/\(\d\+\) \(\d\+\) /\1+\2,/g
C<c-r>=<c-r>"
<Esc><c-o>V}J0i <esc>@qq@qdd:s/ i1/1
```
[Try it online!](https://tio.run/##K/v/36pY3zAmTz@Ry8VBKdNQwSa1ONmOq7AwsiAnJ8cxFsw1yIwG00ClMRoxKTHaMZoKcIZ@jKF2jJGOfjqXs02ybpGdLZhU4rJxBeoAsvPtwmq9DDIhBjsUFjoUpqQADVLINNQ35Pr/39Tsv24ZAA "V (vim) – Try It Online")
Special casing 1 for `<c-o>` was a bit annoying, but the rest plays out smoothly.
Possible byte saves can be in the large regex, and maybe removing the 1 special case.
Outputs as space separated lists.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 7 bytes
```
1ẋ≬2ẇṠ↔
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIx4bqL4omsMuG6h+G5oOKGlCIsIiIsIjEzIl0=)
```
1ẋ      # n 1s
      ↔ # Collect while unique:
  ≬---  # Next three as function
    ẇ   # Cut into chunks of length
   2    # 2
     Ṡ  # Sum each chunk
```
[Answer]
# [Ohm v2](https://github.com/nickbclifford/Ohm), 8 bytes
```
@Dv·Ω2σΣ
```
[Try it online!](https://tio.run/##y8/INfr/38Gl7ND2cyuNzjefW/z/v6EpAA "Ohm v2 – Try It Online")
If output in scientific notation is allowed, otherwise:
# [Ohm v2](https://github.com/nickbclifford/Ohm), 9 bytes
```
@Dv·Ω2σΣì
```
[Try it online!](https://tio.run/##y8/INfr/38Gl7ND2cyuNzjefW3x4zf//hqYA "Ohm v2 – Try It Online")
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 12 bytes
```
ċ)¦⟨:q2/Σ¦⟩ª
```
[Try it online!](https://tio.run/##S0/MTPz//0i35qFlj@avsCo00j@3GMRceWjV//@GpgA "Gaia – Try It Online")
```
ċ)¦		| generate array of n 1's (really, generate array of n 0's and increment each)
   ⟨      ⟩ª	| do the following until you get to a fixed point:
    :q		| dup and print with a newline
      2/	| split into groups of 2, with last group possibly being smaller
	Σ¦	| take the sum
```
]