In these previous challenges[1][2] I've been dealing with "mushroom forests". To help with these I draw little diagrams of the forests to help. In this challenge we are going to reverse engineer the data from these diagrams.
To recap ha! mushroom forests are a list of pairs of non-negative integers. Each pair represents a mushroom whose center is at that horizontal coordinate. The only part of the mushroom we care about is the cap (the flat bit at the top).
The first integer in each pair represents which row the cap is placed in. i.e. the height of the mushroom.
The second integer represents the radius of the cap. If it's zero then there just isn't a mushroom in that position. Other for size \$n\$ a total of \$2n-1\$ spaces are occupied centered at the index of the pair. For example 1
means that its cap only occupies a space above it, a 2
means it occupies a space above it and the spaces one unit to the left and right.
To draw the data I represent rows using lines of text separated by newlines. There are twice as many lines as there are rows with the even rows being used for spacing. I draw the caps using the =
and I only draw caps on odd numbered lines. If a mushroom cap is present at coordinate \$(x,y)\$ I draw an =
at \$(2x,2y+1)\$. Here's an example:
=
= = = = = = = = = = = = = = = = =
= = = = =
= = = =
[ 2,3,9,1,0,1 ] <- Widths
[ 0,1,2,3,2,1 ] <- Heights
Then between =
s of the same height I add an extra =
if they belong to the same mushroom.
=
=================================
=========
===== =
[ 2,3,9,1,0,1 ] <- Widths
[ 0,1,2,3,2,1 ] <- Heights
Then I draw stalks extending from the bottom row up to the cap the correspond to. If there's already a =
in a space I leave it alone. I don't draw any stalks for mushrooms with width 0
.
=
|
=================================
| |
=========
| | |
===== | | =
| | | | |
[ 2,3,9,1,0,1 ] <- Widths
[ 0,1,2,3,2,1 ] <- Heights
Task
Your task is to take as input a string of an ascii diagram as described above and output the list of widths used to draw that diagram. We don't care about the heights at all.
You may output trailing and leading zeros in your result, as they don't change the diagram. You may also assume that the input is padded to a perfect rectangle enclosing the bounding box of the art. You may assume that there is always a valid solution to the input and you do not have to handle malformed input.
This is code-golf so the goal is to minimize the size of your source code as measured in bytes.
Test cases
Test cases are provided with all leading and trailing zeros trimmed in the output, however the output is aligned to the input for clarity.
=
|
=================================
| |
=========
| | |
===== | | =
| | | | |
[2,3,9,1,0,1]
= =
| |
[1,1]
===== =====
| |
[2,0,0,0,0,2]
===== ============= =
| | |
| ===== | =====
| | | | |
===== =========
| | | | | | |
[2,2,2,0,0,4,0,3,2,1]
===== =
| |
===== =========
| | | |
[2,2,0,1,3]
=============
|
=============
| |
===== |
| | |
= | | |
| | | |
===== | | |
| | | | |
[2,1,2,4,4]