Is my emoji dry?
05AB1E, 18 17 15 bytes
Code:
|…-_-123:)ø€J€ï
Explanation:
| # Take all input as a list of strings.
…-_- # 3-char string, which results into "-_-".
123:) # Replace "-_-" with 123.
ø # Zip, resulting into the columns of the 2D array.
€J # Join each of them.
ە # For each, convert to integer. If this is not possible, it will ignore
the result.
# Implicitly output the array.
Uses the CP-1252 encoding. Try it online! (make sure to pad all lines with spaces to the same length..
JavaScript (ES6), 95 bytes
a=>[...a[n=0]].map((_,i)=>a.map(s=>(c=s[i])>"-"&c<"_"?p=1:n+=!++c,p=0)|p<!c&&o.push(n),o=[])&&o
Input should be an array of strings, with each line padded with spaces to form a square. Output is an array of 1-indexed numbers.
Explanation
var solution =
a=>
[...a[n=0]].map((_,i)=> // n = current index of emoji, for each column i of input
a.map(s=> // for each line s
(c=s[i]) // c = character in column
>"-"&c<"_"?p=1 // p = 1 if column is protected from rain
:n+=!++c, // increment n if emoji character found, c = 1 if last line
// contained a space in the current column
p=0
)
|p<!c&&o.push(n), // if the emoji is not protected in the current column
o=[]
)
&&o
<textarea id="input" rows="6" cols="40"> /\
/ \
-_-</textarea><br />
<button onclick="result.textContent=solution(input.value.split('\n'))">Go</button>
<pre id="result"></pre>
JavaScript (ES6), 92 bytes
a=>a.map(s=>s.replace(/\S/g,(c,i)=>c>'-'&c<'_'?u[i]=3:++n&u[i]||r.push(n)),n=0,u=[],r=[])&&r
Accepts a ragged array of lines and returns a 1-indexed result. Explanation:
a=>a.map( Loop through all lines
s=>s.replace(/\S/g, Loop through all non-whitepsace
(c,i)=>c>'-'&c<'_' If it's part of the umbrella
?u[i]=3 Mark that column as dry
:++n& Add 1 to the emoji index
u[i]|| If the column is not dry
r.push(n) Add the emoji index to the result
),n=0,u=[],r=[] Initialise variables
)&&r Return result