21
1
Inspired by Create a binary wall
Given a list of positive integers, we can write them out all above each other like so, for [2, 6, 9, 4]
as an example:
0010
0110
1001
0100
We can imagine this as a wall:
..#.
.##.
#..#
.#..
However, this is a very weak wall, and it has collapsed! Each 1
(#
) falls down until it hits the "ground" or another 1
(#
). The 0
s (.
s) are present in spots left by moved 1
s.
This becomes the following:
....
....
.##.
####
Which translates back to:
0000
0000
0110
1111
Which, as a list of numbers, is [0, 0, 6, 15]
.
Another test case
[10, 17, 19, 23]
This becomes:
01010
10001
10011
10111
which becomes:
00000
10011
10011
11111
translating back to:
[0, 19, 19, 31]
Challenge
Given a list of positive integers, apply this transformation to the list. Input/Output as lists of positive integers in any reasonable format. Standard loopholes apply.
This is a code-golf, so the shortest answer in bytes wins!
Sandbox Post – HyperNeutrino – 2017-07-29T19:36:10.333
1More testcases? You know, non-square testcases would be good. – Leaky Nun – 2017-07-29T19:44:19.023
@LeakyNun Sure. I'll do that. – HyperNeutrino – 2017-07-29T19:44:37.533
That's just a sorting problem for bit arrays. – Marcus Müller – 2017-07-30T19:50:08.397
@MarcusMüller You're right - I realized that after the MATL answer :P – HyperNeutrino – 2017-07-30T20:14:27.617
@TheLethalCoder :) It was a nice challenge :) – HyperNeutrino – 2017-07-31T16:27:59.450