| Bytes | Lang | Time | Link |
|---|---|---|---|
| 196 | Python3 | 240716T155416Z | Ajax1234 |
| 120 | R | 220505T123838Z | Dominic |
| 021 | 05AB1E | 220505T202013Z | Kevin Cr |
| 030 | Charcoal | 220505T185926Z | Neil |
| 021 | J | 220505T130011Z | Jonah |
| 133 | Desmos | 220505T125416Z | fireflam |
| 100 | PARI/GP | 220505T115445Z | alephalp |
| 024 | BQN | 220505T112514Z | ovs |
Python3, 196 bytes
R=range
def f(a,m):
for s in R(len(a)):
M=[a[i:i+s]for i in R(0,len(a),s)]if s else[a]
for x in R(len(M)):
for y in R(len(M[0])):
if[J[y:y+len(m[0])]for J in M[x:x+len(m)]]==m:return 1
R, 126 121 120 bytes
Edit: -5 bytes thanks to Aaron Hayman
function(x,m,r=nrow(m)){for(o in l<-seq(x)-1)for(s in l+o)T=T&any(c(x,!x,!x)[outer(1:r,(r+s)*(1:ncol(m)-1),`+`)+o]-m)
T}
Outputs TRUE if wally isn't there m is not present in any wrapping of x, FALSE if it is.
Calculates the indices of positions of wally m for each possible offset (the first position in the wrapped matrix) and spacing (the width of the wrapped matrix), and checks that the elements of x at these indices are all equal to m.
To avoid lengthly calculations to keep the indices in-range, we first extend x with enough zeros to cover the biggest o & s: this is the ugly-looking (c(x,!x,!x).
05AB1E, 27 21 bytes
.œεεŒIнgù}øεŒIgù€Q]˜à
Try it online or or verify all test cases or try it online with step-by-step debug-lines.
Explanation:
.œ # Get all partitions of the first (implicit) input-list
ε # Map over each partition:
ε # Map over each inner list:
Œ # Get all sublists of this list
I # Push the second input-matrix
н # Pop and leave just its first row
g # Pop and push its length to get the width of the matrix
ù # Only leave all sublists of this length, to get all overlapping
# parts with a size equal to the width of the input-matrix
}ø # After the inner map: zip/transpose; swapping rows/columns
ε # Map over each list of lists:
Œ # Get all sublists of this list
I # Push the second input-matrix again
g # Pop and push its length to get the height of the matrix
ù # Only leave all sublists of this length, to get all matrices
# with the same dimensions as the input-matrix
€ # Map over each inner matrix:
Q # Check if its equal to the second (implicit) input-matrix
] # Close both maps
˜ # Flatten
à # Get the maximum to check if any were truthy
Charcoal, 31 30 bytes
FEθ⪪θ⊕κP⊙ι⊙κ⊙ι⊙ξ⁼ηE✂ιλ⊕π¹✂σν⊕ς
Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - if it finds Wally, nothing if not. Explanation: Another answer that generates all submatrices of all wrappings.
FEθ⪪θ⊕κ
Generate all wrappings of the list.
P⊙ι⊙κ⊙ι⊙ξ⁼ηE✂ιλ⊕π¹✂σν⊕ς
Check whether the matrix exists as a submatrix.
Unfortunately Charcoal only has 11 loop variables so I can't save a further byte like this:
⊙Eθ⪪θ⊕κ⊙ι⊙κ⊙ι⊙ξ⁼ηE✂ιλ⊕π¹✂σν⊕ς
Explanation:
θ Input list
E Map over digits
θ Input list
⪪ Wrapped to width
κ Current index
⊕ Incremented
⊙ Any wrapping satisfies
ι Current wrapping
⊙ Any row satisfies
λ Current row
⊙ Any column satisifies
ι Current wrapping
⊙ Any row satisfies
ξ Inner row
⊙ Any column satisifies
η Input matrix
⁼ Equals
ι Current wrapping
✂ ¹ Sliced from
μ Outer row index to
π Inner row index
⊕ Incremented
E Map over rows
σ Current row
✂ Sliced from
ν Outer column index to
ς Inner column index
⊕ Incremented
Implicitly print
J, 21 bytes
1 e.,@(E."2-@#\]\"{])
Bulk of the work done by E. builtin, which can search for one 2D matrix within another, and even extends to higher dimensions.
-@#\]\"{]Every possible wrapping.E."2Does the matrix match at each position? (returns 0/1 matrices),@Flatten1 e.Is 1 an element of that?
Desmos, 133 bytes
f(L,M,w)=0^{\sum_{m=1}^K\sum_{X=w}^m\sum_{Y=0}^K\prod_{j=0}^{M.\length-1}\{M[j+1]=L[X+Ym+1-w+\mod(j,w)+\floor(j/w)m],0\}}
K=L.length
- L: list of positive digits (x in question)
- M: matrix, flattened because Desmos doesn't have 2D arrays
- w: width of M
Outputs 0 for truthy and 1 for falsey.
PARI/GP, 100 bytes
f(a,b)=sum(n=#b,#a,!!matrix(-#a\-n,n-#b+1,x,y,b==matrix(#b~,#b,i,j,if(#a>=k=(x+i-2)*n+y+j-1,a[k]))))
Generates all possible wrappings, and all of their submatrices of the given size, and check if the second argument is one of them.
BQN, 24 bytesSBCS
Generates all possible wrappings and checks if the left argument is a submatrix of one.
{1∊∾(⥊𝕨⍷𝕩⥊˜⟨↑⟩∾1⊸+)¨↕≠𝕩}