I have list:
words = ["ALI", "SIN", "ASI", "LIR", "IRI", "INI", "KAR"]
I want to check if they form matrix such as this:
and return my solution as a list like:
solution = ["ALI", "SIN", "IRI"]
I have come up with this code:
words=["ALI", "SIN", "ASI", "LIR", "IRI", "INI", "KAR"]
solution =[]
failedsolutions = []
def Get_next_word():
while True:
for word in words:
if (word in solution) == False:
solution.append(word)
if (solution in failedsolutions) == False:
return False
else:
solution.pop(len(solution) - 1 )
return True
def Check_word_order():
checker = True
for i in range(len(solution)):
for j in range(len(words[0])):
for word in words:
if solution[i][j] == word[j]:
checker = False
else:
checker = True
if checker == False:
return checker
def main():
while True:
Get_next_word()
check = Check_word_order()
if check is False:
#Backtrack
failedsolutions.append(solution)
solution.pop(len(solution) - 1 )
# else:
# solution.append()
print(solution)
main()
I am tired and no longer be able to debug my code. Help will be appreciated. Thank you ps: I advice not fixing my code if there is a better way to it all.