Given a string that represents a bunch of tables stacked on top of each other and/or arranged side-by-side, disassemble all the tables.
Tables
A table looks like this:
-------
| |
| |
More formally, a table has a tabletop, composed of n
dashes, and two visible legs. (Obviously, there are two hidden behind, but for the purposes of this challenge, a table has two legs. (Think of the legs as being thick legs that span the entire length of the table.)
The visible legs are both m
pipes (|
) high, and are separated by n-2
spaces. (Thus, the string representation of a table has m+1
lines of exactly n
characters per line.)
Does it sound easy to disassemble a table? Think again.
Stacked tables and tables arranged side-by-side
The table above is just one of the many tables you could be given as input. In actuality, oftentimes you will have a huge number of tables you wish to disassemble, and to save space in your home, you might decide to stack them on top of each other, and sometimes arrange these stacks side-by-side.
This would not be a problem if the tables were all the same height and length. However, obviously there is the possibility of having a messy arrangement of tables, and you should be able to disassemble these arrangements as easily as you would disassemble a single table.
This is an example of an arrangement:
---------
| | ---
| | | |
------------- -------------------
| | | |
--------------- | |
| | | |
| |-----------------------------------
| || |
| || |
How to disassemble tables, or arrangements thereof?
Disassembling tables consists of separating the top, leg one, and leg two from each other. Your answer to this challenge should output these separated parts in their appropriate orientation.
For instance, when disassembling the single table shown in the section "Tables", you should get the following:
-------
| |
| |
Disassembling the complex arrangement above gives this:
--------- --- ------------- ------------------- --------------- -----------------------------------
| | | | | | | | | | | |
| | | | | | | |
| | | |
| |
Your answer to this challenge can choose to output in this neat format, where the tops are laid next to each other at the top of the output and all the legs are laid next to each other below the tops, with all the parts in their correct orientation, or you can choose to output a list of all the parts, but in the correct orientation. What you may not do, however, is output the input unchanged and say "look, all the parts are there". To assess whether an output format is reasonable, determine whether or not the output format shows a clear separation between the parts. You may output the parts in any order, as long as the output format remains reasonable. (No outputting full tables, for instance.) Note also that if outputting in the neat format, all tabletops must be at the top of the output, and the legs below all the tabletops. However, the order of the tabletops and the order of the legs are both flexible.
Additionally, output may also be in the form of two lists, one representing a list of tabletop lengths and one representing a list of leg lengths. This output form may only be used if the lists are clearly separate.
Input may be ASCII art as shown above, a list of lines, or a character matrix.
More examples
Input:
--
||
Output, which will hereinafter be in the neat format:
--
| |
Why? Your answer should not treat ||
as one leg; a leg is only one pipe "thick".
Input:
----
||||
Output:
-- --
| | | |
Why? Tables have only two legs. Once your answer sees the first leg of a table, it should only treat the area from that leg until the next leg it sees, as a table. Thus, there are two tables in the above example, not one.
Input:
---------
| || |
Output:
----- ----
| | | |
Why? See above.
Input:
---
| |---
---| |
| || |
Output:
--- --- ---
| | | | | |
| |
Input:
---
| |
--------
||| |
Output:
--- -- ------
| | | | | |
Input:
---
---------------------------| |
| || |
| || |
| || |
------------------------------
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
Output:
--------------------------- --- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| |
More notes
You may assume that tables will not be "completely underneath tables", that is, no input like this will be given:
--------------------
| |
| ------- |
| | | |
| | | |
You may assume that the arrangement is "stable", so there are no legs "hanging in midair":
-----------------
| | <- this leg is hanging in midair
| |
----------
| |
On a related note, the heights of the legs of a table are the same (this is stated above, but I want to make it extremely clear). This means that this input will not be given:
-----------
| |
------- |
| | |
You may assume that tables are stacked only in the correct orientation, so no arrangements like this:
|-------
|
|
|-------
-----------
| |
or this:
| |
| |
| |
-------------
-------------
| |
This is code-golf, so the shortest code, measured in bytes, wins.