21
1
Someone has been hastily stacking the Christmas presents, and it's quite a mess:
========================
| |
========================
=============
| |
| |
| |
| |
| |
| |
=============
=======
| |
| |
| |
=======
===================
| |
| |
| |
===================
=================
| |
| |
| |
| |
=================
=======
| |
| |
=======
Like, seriously, how does that top present even balance. It's probably a hammer. To prevent this tower of presents from crumbling, you're to reorder the presents so they stack nicely:
=======
| |
| |
=======
=======
| |
| |
| |
=======
=============
| |
| |
| |
| |
| |
| |
=============
=================
| |
| |
| |
| |
=================
===================
| |
| |
| |
===================
========================
| |
========================
The Rules
- Each present consists of a top and bottom of
=
characters, and one or more middle rows, consisting of two|
separated by spaces. The width of the present is the same in all its rows. - There are no empty lines.
- Consecutive presents will overlap in at least one column.
- Presents are to be stacked in order of decreasing width. In the event of a tie, the taller present should go below the flatter present.
- Presents should be centred on the present beneath. If the present cannot be placed exactly in the centre (because the difference in widths is odd), you may choose either position that is half a character off the centre.
- You may or may not assume that the input has a single trailing newline, but please state your assumption.
- Your solution does not have to work for an empty input, but must be able to handle a single present.
- You may write a program or function, which takes input via STDIN or function argument and returns the result or prints it to STDOUT.
- This is code golf, so the shortest answer (in bytes) wins.
That's awesome that the standard lexicographic order happens to fulfill the sorting requirements! Nice catch. – wchargin – 2014-12-25T00:59:08.150
@WChargin yeah. Saved me a ton of bytes! – Optimizer – 2014-12-25T01:02:55.573