29
5
Here is an example of an input of monoliths. There are 4 in this example.
_
| | _
| | _ | |
| | | | | | _
_| |_| |___| |____| |_
The first monolith is 4 units high, the second is 2, the third is 3, and the last is 1.
The task
Your program should output the heights of the monoliths in order from left to right. The output format can be in any sort of list or array.
Notes
- The input can be taken as any dimensional string, list of strings, or list of characters.
- This is code-golf, so lowest bytes wins.
- You are to assume that monoliths always have the same width, and are always at least 1
_
away from another. - They can come in any height, and in any quantity.
I/O
_
| | _
| | _ | |
| | | | | | _
_| |_| |___| |____| |_ >> [4,2,3,1]
_
| |
_ | |
| | _ | | _
_| |_| |__| |_| |_ >> [2,1,4,1]
_ _ _
| |_| |_| |_____ >> [1,1,1]
____________________ >> undefined behavior
_
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | >> [11]
_ _ _ _ _
_ | | _ | | _ | | _ | | _ | |
| |_| |_| |_| |_| |_| |_| |_| |_| |_| | >> [1,2,1,2,1,2,1,2,1,2]
2May I assume the input is right padded with spaces? – isaacg – 2017-06-30T02:46:51.567
17Is your
[10]
monolith not[11]
? – TessellatingHeckler – 2017-06-30T06:47:52.817Wouldn't the undefined one just be an empty array? – Solomon Ucko – 2017-07-01T02:03:30.137
@isaacg yes, that would be okay – Graviton – 2017-07-01T03:01:54.607
@SolomonUcko technically yes, though to make it simpler for all languages I decided to not have them deal with it. – Graviton – 2017-07-01T03:02:44.957
Ok. So basically, you can implement it like that, but don't have to? – Solomon Ucko – 2017-07-01T13:52:09.477
@SolomonUcko Yes, exactly. Primarily because some algorithms might fail at that test, and have to create more code just for that exception. Which drives the average byte count up (which is no fun). – Graviton – 2017-07-01T18:30:18.287
I see, that makes sense. – Solomon Ucko – 2017-07-02T12:40:26.977