12
1
Given two non-empty non-negative integer matrices A and B, answer the number of times A occurs as a contiguous, possibly overlapping, submatrix in B.
Examples/Rules
0. There may not be any submatrices
A:
[[3,1],
[1,4]]
B:
[[1,4],
[3,1]]
Answer:
0
1. Submatrices must be contiguous
A:
[[1,4],
[3,1]]
B:
[[3,1,4,0,5],
[6,3,1,0,4],
[5,6,3,0,1]]
Answer:
1
(marked in bold)
2. Submatrices may overlap
A:
[[1,4],
[3,1]]
B:
[[3,1,4,5],
[6,3,1,4],
[5,6,3,1]]
Answer:
2
(marked in bold and in italic respectively)
3. A (sub)matrix may be size 1-by-1 and up
A:
[[3]]
B:
[[3,1,4,5],
[6,3,1,4],
[5,6,3,1]]
Answer:
3
(marked in bold)
4. Matrices may be any shape
A:
[[3,1,3]]
[[3,1,3,1,3,1,3,1,3]]
Answer:
4
(two bold, two italic)
You should checkout
⍷
– H.PWiz – 2019-01-02T03:57:27.517you can use compose (
∘
) to shorten the train:+/∘∊⍷
or even≢∘⍸⍷
– ngn – 2019-01-02T15:16:47.757