How can I shift and merge elements of a matrix to have the following result ?
Move right:
[[0,0,2,2,0,2],[8,4,2,2,0,2]]
==> [[0,0,0,0,4,2],[0,0,8,4,4,2]]
or
Move left:
[[0,0,2,2,0,2],[8,4,2,2,0,2]]
==> [[4,2,0,0,0,0],[8,4,4,2,0,0]]
It's like the 2048 game. For example, when the user do a left move, every numbers go to the left of the list and if 2 numbers side-by-side are equals, tere is an addition of the two numbers.
I would like to do it with loops.
I tried with some codes that I have found on the internet but as a begineer, I didn't found a straightforward code to understand how to do this.
Thanks in advance for the help.