# [CentralOH] DoJo Problem for Tonight

neil ludban neil.ludban at gmail.com
Thu Mar 21 21:27:26 EDT 2019

```#!/usr/bin/env python3.7

def row_generator(p):
for row in p:
yield ''.join(row)

def col_generator(p):
for col in zip(*p):
yield ''.join(col)

def word_in_puzzle(w, p):
for x in row_generator(p):
if w in x:
return True
for x in col_generator(p):
if w in x:
return True
return False

puzzle = [
[ 'F', 'A', 'C', 'I' ],
[ 'O', 'B', 'Q', 'P' ],
[ 'A', 'N', 'O', 'B' ],
[ 'M', 'A', 'S', 'S' ],
]

print(word_in_puzzle('FOAM', puzzle))
print(word_in_puzzle('MASS', puzzle))

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/a793477c/attachment.html>
```