递归内核的问题死亡,重新启动

时间:2018-11-17 10:36:50

标签: python python-3.x algorithm

所以我想做的是在填字游戏中找到单词,单词可以是水平,后水平,对角线,对角线,反对角线,单词内的单词。 找到它们之后,我要删除填字游戏中找到的单词,并按填字游戏的顺序返回其余字母。

我将为您努力,将减少一些代码,因为我必须在txt文件中使用填字游戏和单词。

给定填字游戏:

COIHCCEPSB
INOIZIRFIA
EDENTIAGAC
TECASCOROC
NOHPMDUINO
ESAEITLNIN
NPNNNGAODC
AAIIAOCINI
MZTTIMCZAA
RZETIOAOVT
EORELLSLAU
PLAPIEGALR
MANICURERE

单词:

['ACCONCIATURE', 'BIGODINI', 'CASCO', 'DENTI', 'FRIZIONI', 'LACCA', 'LAVANDINO', 'LOZIONI', 'MANICURE', 'ONDE', 'PERMANENTE', 'PETTINE', 'PHON', 'PIEGA', 'RASOI', 'RETINA', 'SPAZZOLA', 'SPECCHIO', 'TAGLIO', 'TINTURA']

到目前为止,我的代码是:

dict1 = {}
for r,x in enumerate(crossword.split("\n")):
    for c,y in enumerate(x):
        dict1[(r,c)] = y # Puts in dict1 the locations as a keys and letters as values

found = []
for word in words:
    for currentPos in dict1.keys():  
        for cords in searcWord(dict1,word,currentPos,[]): #calling searcWord with the dict1 ,with the current word and current location, and empty list that shoud be returned if the whole word matches. 
            found.append(cords)

def searcWord(dict1,word,currentPos,cords):
    cordsReturn = []
    for DirectionR in [-1,0,1]: #Going through the directions in the row
        for DirectionC in [-1,0,1]: #Going through the directions in the column 
            for newPath in searcWord(dict1, word[1:],(currentPos[0]+DirectionR,currentPos[1]+DirectionC), [currentPos]+cords):#calling again the function with the next letter in the word in the direction found.
                cordsReturn.append(newPath)
                return cordsReturn

问题是它给了我

“ RecursionError:超过最大递归深度”, 我放

“导入系统 sys.setrecursionlimit(5000)“ 但比起“内核死亡,重新启动”

如果不清楚,请告诉我,我会尽力使其更清晰。

0 个答案:

没有答案