Your challenge is given an input of a prison layout to work out whether any of the prisoners can escape.
Input
Input may be in any reasonable format such as a string, array, array of arrays etc. The input will consist of three characters, in this case #
, P
and space. The input will not necessarily contain all three characters.
#
: A wallP
: A prisoner- space: An empty space
An example input will look like:
#####
# #
# P #
# #
#####
Output
A truthy/falsey value of whether or not the prison is secure. The prison is only secure if it can hold all of the prisoners. If any prisoner can escape it is not secure.
A prisoner can escape if they are not fully enclosed by a wall. A diagonal joining is fully enclosed.
Test cases
############# Truthy
# P # P# #
# # # P #
#############
############# Truthy
# P P #
# # # P #
#############
############# Falsey
# P # P# #
# # # P #
########## ##
#### Truthy
# #
# #
# P ####
####
P Falsey
### Falsey
# #
# #
### P