MATL, 29 28 24 bytes
z2Y6ttX*,GbZ+5Mz=z]yytvs
Try it online! Input is a binary matrix with 1
for '+'
and 0
for '-'
.
Try it online! Or verify all test cases.
Explanation
3\z % Implicit input. Modulo 3 (of ASCII codes), element-wise. This produces
% a binary matrix with 1 for '+', 0 for '-'
XK % Copy into clipboard K
z % Number of nonzeros. This is the number of naive pluses
2Y6 % Push [0 1 0; 1 1 1; 0 1 0] (predefined literal): pattern of double plus
ttX* % Duplicate twice. Kronecker product: pattern of mega-double plus
, % Do twice
KG % Push input as binary matrixagain
b % Bubble up third-topmost entry in the stack. This moves either the
% double of mega-double pattern to top
Z+ % 2D convolution, maintaining size
5M % Push the last input to the last function again: the pattern
z % Number of nonzeros. This gives 5 or 25 for double or mega-double
= % Equal? Element-wise. This detects if the result of the convolution
% equals the number of ones in the pattern, which implies that the
% pattern has been found
z % Number of nonzeros. This is how many times the pattern has been found
] % End
yyt % Duplicate the top two elements, then the top element. This effectively
% gives weight 2 and 3 to double and mega-double pluses
vs % Concatenate all stack contents. Sum. Implicit display