This was inspired by this question. Given an \$m\times n\$ matrix of \$0\$'s and \$1\$'s, apply "gravity" to it. This means to drop down all the \$1\$'s as if they were affected by gravity.
For example
[[1,0,1,1,0,1,0]
[0,0,0,1,0,0,0]
[1,0,1,1,1,1,1]
[0,1,1,0,1,1,0]
[1,1,0,1,0,0,1]]
Should result in
[[0,0,0,0,0,0,0]
[0,0,0,1,0,0,0]
[1,0,1,1,0,1,0]
[1,1,1,1,1,1,1]
[1,1,1,1,1,1,1]]
As all \$1\$'s have been dropped down.
input
Input will be atleast \$1\times 1\$. You may take input in all reasonable forms (Bitsets, arrays, Lists) and either output the result, return a new Bitset, array or list or simply modify the input.
This is code golf, so the answer with the fewest bytes wins!
test-cases
More test-cases:
[[1,0] [[0,0]
[0,0] -> [1,0]
[1,0]] [1,0]]
[[1,1,1,1,1] [[1,0,1,1,0]
[1,0,1,1,0] -> [1,1,1,1,0]
[1,1,1,1,0]] [1,1,1,1,1]]
[[1]] -> [[1]]
The brackets are just there to visualize arrays, they are not required in your output!
11111-10110-11110
for a 3×4 matrix (the second testcase). And assuming so, can-
be replaced by any delimiter aside from 0 & 1? \$\endgroup\$