[CentralOH] DoJo Problem for Tonight
winningham at gmail.com
Thu Mar 21 16:12:53 EDT 2019
I tried to make a one-liner for this. I can imagine a possibly simpler
NumPy based idea though maybe? Essentially joins the strings by column and
then simply by row, appends both of those, and then tests for membership.
This would not find partial matches.
the_matrix=[['F', 'A', 'C', 'I'],
['O', 'B', 'Q', 'P'],
['A', 'N', 'O', 'B'],
['M', 'A', 'S', 'S']]
test_function = lambda t : t in [
''.join([y[z] for y in the_matrix])
for z in range(len(the_matrix))] + [
''.join(y) for y in the_matrix]
On Thu, Mar 21, 2019 at 3:39 PM Travis Risner <deeppunster at gmail.com> wrote:
> Hi folks,
> If you are interested, here is a problem to consider for tonight’s
> Given a 2D matrix of characters and a target word, write a function that
> returns whether the word can be found in the matrix by going
> left-to-right, or up-to-down.
> For example, given the following matrix:
> [['F', 'A', 'C', 'I'],
> ['O', 'B', 'Q', 'P'],
> ['A', 'N', 'O', 'B'],
> ['M', 'A', 'S', 'S']]
> and the target word 'FOAM', you should return true, since it's the
> leftmost column. Similarly, given the target word 'MASS', you should
> return true, since it's the last row.
> See you tonight!
> CentralOH mailing list
> CentralOH at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH