Bugfix.
This commit is contained in:
parent
40bb7b6585
commit
438251c52d
25
solve.py
25
solve.py
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
WORDLIST="web2.txt"
|
#WORDLIST="web2.txt"
|
||||||
|
WORDLIST="mbsingle.txt"
|
||||||
|
|
||||||
#SQUARE="NRONACNELEGOOESLEIEECIDEAIRBBTBODETS"
|
#SQUARE="NRONACNELEGOOESLEIEECIDEAIRBBTBODETS"
|
||||||
#SQUARE="DUAEAYURIZESAEIRLPESPESRSSESSAPPSEED"
|
#SQUARE="DUAEAYURIZESAEIRLPESPESRSSESSAPPSEED"
|
||||||
@ -12,7 +13,8 @@ WORDLIST="web2.txt"
|
|||||||
#SQUARE="NNREDCTEMAROACRAMEEIAIMTONCTETERESEC"
|
#SQUARE="NNREDCTEMAROACRAMEEIAIMTONCTETERESEC"
|
||||||
#SQUARE="NEREILGEDENALRLELRIGNAATREONALETUGTE"
|
#SQUARE="NEREILGEDENALRLELRIGNAATREONALETUGTE"
|
||||||
#SQUARE="FNADIHALNARTANUUGIANFALNSCGNTATRICTS"
|
#SQUARE="FNADIHALNARTANUUGIANFALNSCGNTATRICTS"
|
||||||
SQUARE="RRCOLALAALETSTEIIRSATSTRRECCAEOSEHRE"
|
#SQUARE="RRCOLALAALETSTEIIRSATSTRRECCAEOSEHRE"
|
||||||
|
SQUARE="LAGECSERDONOTEINERIDTREEDONLDGARTTDE"
|
||||||
word_len = math.sqrt(len(SQUARE))
|
word_len = math.sqrt(len(SQUARE))
|
||||||
|
|
||||||
print("Word length: %i" % word_len)
|
print("Word length: %i" % word_len)
|
||||||
@ -39,7 +41,7 @@ for l in letters:
|
|||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
|
|
||||||
f = open("web2.txt", "r")
|
f = open(WORDLIST, "r")
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip().upper()
|
line = line.strip().upper()
|
||||||
# check word length
|
# check word length
|
||||||
@ -92,25 +94,32 @@ def try_solve(letters, words = [], max_level = 99):
|
|||||||
start_letters += words[i][level]
|
start_letters += words[i][level]
|
||||||
# if level == max_level -1:
|
# if level == max_level -1:
|
||||||
# print("Prefix: %s, letters: %s" % (start_letters, repr(letters)))
|
# print("Prefix: %s, letters: %s" % (start_letters, repr(letters)))
|
||||||
|
# print("Prefix: %s" % start_letters)
|
||||||
next_matches = []
|
next_matches = []
|
||||||
for w in candidates:
|
for w in candidates:
|
||||||
if w[:level] != start_letters:
|
if w[:level] != start_letters:
|
||||||
continue
|
continue
|
||||||
rem_letters = check_valid(w[level:], letters.copy())
|
rem_letters = check_valid(w[level:], letters.copy())
|
||||||
if type(rem_letters) is dict:
|
if type(rem_letters) is dict:
|
||||||
|
# print("Match: %s" % w)
|
||||||
# next_matches.append(w)
|
# next_matches.append(w)
|
||||||
if len(rem_letters)>0:
|
if len(rem_letters)>0:
|
||||||
|
# print("Letters left.")
|
||||||
more = try_solve(rem_letters.copy(), words + [w], max_level)
|
more = try_solve(rem_letters.copy(), words + [w], max_level)
|
||||||
|
# print(more)
|
||||||
if more:
|
if more:
|
||||||
next_matches.append((w, more))
|
next_matches.append((w, more))
|
||||||
else:
|
else:
|
||||||
|
# print("No letters left.")
|
||||||
next_matches.append(w)
|
next_matches.append(w)
|
||||||
return next_matches
|
return next_matches
|
||||||
|
|
||||||
#rem_first = check_valid("BEACON", letters.copy())
|
#rem_first = check_valid("CORRAL", letters.copy())
|
||||||
#rem_second = check_valid("NROBE", rem_first.copy())
|
#result = try_solve(rem_first.copy(), ["CORRAL"])
|
||||||
|
#rem_second = check_valid("LEATE", rem_first.copy())
|
||||||
#print(rem_second)
|
#print(rem_second)
|
||||||
#result = try_solve(rem_second.copy(), ["BEACON", "ENROBE"])
|
#result = try_solve(rem_second.copy(), ["CORRAL", "OLEATE"])
|
||||||
|
|
||||||
result = try_solve(letters.copy(), max_level=5)
|
result = try_solve(letters.copy())
|
||||||
print(result)
|
#result = try_solve(letters.copy(), max_level=4)
|
||||||
|
print(result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user