[CentralOH] DoJo Problem for Tonight

Thomas Winningham 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[0]))] + [
  ''.join(y) for y in the_matrix]

>>> test_function('FOAM')
True
>>> test_function('FOA')
False
>>> test_function('FOAMS')
False
>>> test_function('MASS')
True
>>> test_function('MAS')
False

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
> meeting.
>
> ————————
>
> 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!
>
> Travis
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20190321/83611c04/attachment.html>


More information about the CentralOH mailing list