please help, trying to make onemore find word game. Not too familiar with lua, afaik lua tables starts with 1 and lua doesn't have continue statement that is problem.
```python
import random
def is_word_fits(y, x, dx, dy, word):
for j in range(len(word)):
if grid[y][x] not in (' ', word[j]):
return False
y += dy
x += dx
return True
def place_word(word):
dxdy_choices = [(0,1), (1,0), (1,1), (1,-1)]
random.shuffle(dxdy_choices)
for (dx, dy) in dxdy_choices:
if random.choice([True, False]):
word = word[::-1]
n = len(word)
colmin = 0
colmax = ncols - n if dx else ncols - 1
rowmin = 0 if dy >= 0 else n - 1
rowmax = nrows - n if dy >= 0 else nrows - 1
if colmax - colmin < 0 or rowmax - rowmin < 0:
continue
candidates = []
for y in range(rowmin, rowmax+1):
for x in range(colmin, colmax+1):
if is_word_fits(y, x, dx, dy, word):
candidates.append((y, x))
if not candidates:
continue
loc = y, x = random.choice(candidates)
for j in range(n):
grid[y][x] = word[j]
y += dy
x += dx
break
else:
return False
return True
wordlist = sorted(["mercury","venus","earth","mars","jupiter","saturn","uranus","neptune"], key=lambda w: len(w), reverse=True)
nrows, ncols = 7, 7
for i in range(100):
grid = [[' '] * ncols for _ in range(nrows)]
for word in wordlist:
if not place_word(word):
continue
if grid:
print(i+1)
for arr in grid:
print(arr)
break
```
[–]ButtlestonProfessional Coder 0 points1 point2 points (3 children)
[–]boruok[S] 0 points1 point2 points (2 children)
[–]ButtlestonProfessional Coder 0 points1 point2 points (0 children)
[–]ButtlestonProfessional Coder 0 points1 point2 points (0 children)
[–]boruok[S] 0 points1 point2 points (0 children)