Skip to main content
deleted 97 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

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

Convolution is the key to success

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

MATL, 29 28 24 bytes

z2Y6ttX*,GbZ+5Mz=z]yytvs

Try it online! Or verify all test cases.

Explanation

Convolution is the key to success

3\      % 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
  K     %   Push input as binary matrix
  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

MATL, 29 28 24 bytes

z2Y6ttX*,GbZ+5Mz=z]yytvs

Input is a binary matrix with 1 for '+' and 0 for '-'.

Try it online! Or verify all test cases.

Explanation

Convolution is the key to success

z       % Implicit input. 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
  G     %   Push input again
  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
added 261 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 29 2828 24 bytes

3\XKz2Y6ttX*z2Y6ttX*,KbZ+5Mz=z]yytvsGbZ+5Mz=z]yytvs

Try it online!Try it online! Or verify all test casesverify all test cases.

Explanation

Convolution Convolution is the key to successis the key to success

3\      % 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
  K     %   Push input as binary matrix
  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

MATL, 29 28 bytes

3\XKz2Y6ttX*,KbZ+5Mz=z]yytvs

Try it online! Or verify all test cases.

Explanation

Convolution is the key to success

3\      % 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
  K     %   Push input as binary matrix
  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

MATL, 29 28 24 bytes

z2Y6ttX*,GbZ+5Mz=z]yytvs

Try it online! Or verify all test cases.

Explanation

Convolution is the key to success

3\      % 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
  K     %   Push input as binary matrix
  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
added 1314 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 29 28 bytes

3\XKz2Y6ttX*,KbZ+5Mz=z]yytvs

Try it online! Or verify all test cases.

Explanation

Convolution is the key to success

3\      % 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
  K     %   Push input as binary matrix
  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

MATL, 29 28 bytes

3\XKz2Y6ttX*,KbZ+5Mz=z]yytvs

Try it online! Or verify all test cases.

MATL, 29 28 bytes

3\XKz2Y6ttX*,KbZ+5Mz=z]yytvs

Try it online! Or verify all test cases.

Explanation

Convolution is the key to success

3\      % 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
  K     %   Push input as binary matrix
  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
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading