+ 1
How do you find out if 2x2 square Is in 2d list in Python?
Hi, I have a small problem. I need to build a function, that would tell me if 2x2 square is in the entered 2d list (returns True or False). Let's say, that the 2x2 square would be word "help". It doesn't matter on the order of the letters. For example 2d list: [ ['x', 'e', 'h'] ['x', 'l', 'p'] ['x', 'x', 'x'] ] Returns True But you can have also 2d list like this: [ ['p', 'e', 'h'] ['x', 'l', 'p'] ['x', 'x', 'l'] ] Returns True aswell But 2d list like this: [ ['x', 'e', 'x'] ['x', 'p', 'x'] ['l', 'x', 'h'] ] Returns False Also it doesn't matter if the list is 3x3 or 50x70, i want the program to work with every possible 2d list. I will appreciate all your ideas. And also sorry for my bad english.
6 Answers
+ 1
Okay so here's the live tester,
https://www.sololearn.com/compiler-playground/cX41gjIKBEBq
if you want to take a look.
0
So some rough logic but perhaps something along this logic
hasSquare(n,nVals,arr) for example.
you can then iterate through arr based on n grabbing the rows and columns,
checking to make sure it index is within the range of the array of course.
grab a nxn column as the raw data
and compare it to nVals,
returning True as soon as it finds a match,
or False if no match is found once it's done processing the arr.
0
I actually don't understand your solution well š
i sent you a msg si we do not spam this comm section
0
Messages don't work so well on desktop, or at all. I'll try to set this up as a public code bit you can run on my profile.
0
Or you can add me on discord And send it there: CallMeJohny#0030 It's up to you
0
CallMeJohny
you would be doing a rolling window view on the array and comparing the sorted flattened view with your sorted flattened target array.
https://code.sololearn.com/c8N5a0sCM0YO/?ref=app