Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solution for team A
** instructions : **
you can simply run it on a text editor or any IDLE, First you must enter each row of the matrix ( seperate each char by **space** ) after you are done adding rows to the matrix , press 'Enter' (input empty) then you can enter the **Key word**
Explanation
There are two main functions and a couple of utility functions to keep the code clean.
the two main fucntions are **identifier() & scavenger() ** ,
Scavenger
this is recursive function and this function is being called from the identifier at the first place for every index in the matrix, and the i , j indexes of the matrix as well as the keyword and a counter representing the # of matched characters are being passed to it as arguments.
if the counter == length of the word
i
th character of the keyword is not matching with the mtx[i][j] character of the matrix or any of the indexes exceed the boundaries of the matrix, the function will return False,i
th andj
th indexes to traverse the matrix in all 4 different directions( left, right, top, down) until one of the indexes goes out of bounds.count
th character is matching and so we replace it by-
before calling the recursive functions so we would not visit it again, but we switch it back to its original character, incase if we failed to match the rest of the sentence.identifier() is being called from the main , and at the end returns the boolean value to the main
the identifier at first checks for the validity of the input matrix and keyword and if they were acceptable, runs a for loop on each index of the matrix, and in each iteration calls the scavenger by passing corresponding attributes to it.
if the result of scavenger() is true , the true value is returned, otherwise the loop continues until we run out of indexes in the matrix and then returns false.
** the comments are pretty descriptive and they explain each step of the process**
PS: the way I implemented the
count
was not my idea, I originally wanted to create a boolean matrix with the same size as the original one and keep the track of each index separately, but then I realized recursion would not be possible ( or not simple) and in order for that to work, I had to approach the iterative method and so the time complexity would have been way worse. that is why you may also see some commented lines holding variablebool_matrix