I heard somewhere that one thing that technology cannot do yet is fold towels1. So it is now your job to prove that statement false!
Given a string as input, made up of rectangles (towels), like the following, fold each towel in half twice. For example:
+------+ +------+ +--+
| | | | | |
| | | | | |
| | -> +------+ -> +--+
| |
| |
| |
+------+
Notice that when a towel is folded, it is first folded up, then from left to right. You program must mimic this behavior as well. Also notice that in the test cases, the towels stays in the same place, but folded.
Rules:
- Standard methods of input/output.
- Standard loopholes apply.
- Input and output should be as a string.
- Trailing whatevers are okay in output, as long as the towels are in the right place relative to each other.
- You may assume that the length of each side of the towel will always be divisible by 2.
- The towels passed as input will always be rectangular.
The towels will always be separated-- however, they may be separated by variable amounts.
code-golf, so shortest code wins!
Test cases:
Input:
+------+
| |
| |
| |
| |
| |
| |
+------+
Output:
+--+
| |
| |
+--+
Input:
+--+ +--+ +--+
| | | | | |
| | | | | |
+--+ +--+ +--+
Output:
++ ++ ++
++ ++ ++
Input:
+----+
| |
| |
| |
| | ++
+----+ ++
Output:
+-+
| |
+-+
+
Input:
+--+
+--+ ++
||
||
++
Output:
++
+
+
1: This has been disproved by Geobits and Laikoni. However, I did hear it somewhere.