Simulate move left for 2048 I have a fixed length vector of 4 elements. The inputs of which are always 0 or 2^n for n = 1 to 15 (so n = 0 excluded i.e.  2^0 = 1 will not appear)

x = [32, 4, 4, 8]

the result should be

x = [32, 8, 8, 0]

The way it works is that values that are the same will get combined, but one it's combined it can not be combined with another value for another turn.

and we want to simulate the shortest code to make simulate 2048 move left on this one row. 

The shortest code wins! It's fixed-size 4 vector. So it's not the same as the other problem. Also, you need to put zeros here. 

Test cases:

[0,0,0,0] -&gt; [0,0,0,0]
[0,0,0,2] -&gt; [2,0,0,0]
[2,0,0,4] -&gt; [2,4,0,0]
[8,0,0,8] -&gt; [16,0,0,0]
[16,16,32,64] -&gt; [32,32,64,0]
[16,16,8,8] -&gt; [32,16,0,0]
[2,2,2,0] -&gt; [4,2,0,0]
APL (Dyalog Unicode), 36 bytesSBCS



Anonymous tacit prefix function.

⎕UCS{4↑⍺⍺t⎕R(1⌽∪¨t←2/¨⍺⍺2*⍳16)⍺⍺⍵~0}


Try it online!

⎕UCS{…} derived function where ⍵ is the argument and ⍺⍺ converts to/from code points:

 ⍵~0 the argument without zeros

 ⍺⍺ convert to code points

 t⎕R(…) Replace the texts t (defined below) with the corresponding texts from:

  ⍳16 the indices from 1 to 16

  2* two raised to the power of those

  ⍺⍺ convert them to characters

  2/¨ make two of each

  t← assign to t

  ∪¨ get the unique element from each (i.e. deduplicate them)

  1⌽ cyclically rotate the first string to the end

 ⍺⍺ convert to code points

 4↑ take the first four elements, padding with zeros