fix solve
This commit is contained in:
parent
37671dd4d6
commit
01cac1c4af
File diff suppressed because one or more lines are too long
20
solve.py
20
solve.py
@ -5,8 +5,9 @@ from lib import cat_words, INSTRUCTIONS, BLANK, ROUNDS, DEBUG, DICTIONARY
|
||||
|
||||
def remove_non_letters(word, non_letters, unconsumed_letters, non_pos_unconsumed_letters):
|
||||
for non_letter in non_letters:
|
||||
if non_letter in word and non_letter in unconsumed_letters and non_letter in non_pos_unconsumed_letters:
|
||||
return True
|
||||
if non_letter in word:
|
||||
if non_letter in unconsumed_letters or non_letter in non_pos_unconsumed_letters:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@ -23,17 +24,19 @@ def remove_positional_letters(word, positional_letters):
|
||||
return rv, unconsumed_letters
|
||||
|
||||
|
||||
def remove_non_positional_letters(word, non_positional_letters):
|
||||
rv, unconsumed_letters = False, ''
|
||||
def remove_non_positional_letters(word, non_positional_letters, unconsumed_letters):
|
||||
rv, non_pos_unconsumed_letters = False, ''
|
||||
for non_pos_idx, non_positional_letter in enumerate(non_positional_letters):
|
||||
if non_positional_letter == BLANK:
|
||||
continue
|
||||
unconsumed_letters += word[non_pos_idx]
|
||||
non_pos_unconsumed_letters += word[non_pos_idx]
|
||||
if non_positional_letter in unconsumed_letters:
|
||||
unconsumed_letters = unconsumed_letters.replace(non_positional_letter, '', 1)
|
||||
if non_positional_letter not in word:
|
||||
rv = True
|
||||
elif word[non_pos_idx] == non_positional_letter:
|
||||
rv = True
|
||||
return rv, unconsumed_letters
|
||||
return rv, non_pos_unconsumed_letters, unconsumed_letters
|
||||
|
||||
|
||||
def round_words(non_letters, all_positional_letters, all_non_positional_letters, dictionary=DICTIONARY):
|
||||
@ -48,7 +51,8 @@ def round_words(non_letters, all_positional_letters, all_non_positional_letters,
|
||||
continue
|
||||
# Find non-positional letters, e.g. h-s--
|
||||
for non_positional_letters in all_non_positional_letters:
|
||||
skip, non_pos_unconsumed_letters = remove_non_positional_letters(word, non_positional_letters)
|
||||
skip, non_pos_unconsumed_letters, unconsumed_letters = remove_non_positional_letters(
|
||||
word, non_positional_letters, unconsumed_letters)
|
||||
if skip:
|
||||
break
|
||||
if skip:
|
||||
@ -157,11 +161,13 @@ def do_test():
|
||||
assert [w for w in round_words('', ['towns'], ['-----'], dictionary=['towns'])] == ['towns']
|
||||
assert [w for w in round_words('', ['-----'], ['stown'], dictionary=['towns'])] == ['towns']
|
||||
assert [w for w in round_words('', ['----y'], ['-----'], dictionary=['slily'])] == ['slily']
|
||||
assert [w for w in round_words('', ['-----'], ['yy---'], dictionary=['slyly'])] == ['slyly']
|
||||
assert [w for w in round_words('', ['----y'], ['y----'], dictionary=['slyly'])] == ['slyly']
|
||||
assert [w for w in round_words('', ['---yy'], ['y----'], dictionary=['slyyy'])] == ['slyyy']
|
||||
assert [w for w in round_words('', ['---yy'], ['-----'], dictionary=['slyyy'])] == ['slyyy']
|
||||
assert [w for w in round_words('', ['-y---'], ['--y--'], dictionary=['sysys'])] == ['sysys']
|
||||
assert [w for w in round_words('nu', ['-o-ns'], ['-----'], dictionary=['towns'])] == ['towns'] # nouns
|
||||
assert [w for w in round_words('r', ['p-int'], ['-----'], dictionary=['print', 'point'])] == ['point']
|
||||
assert [w for w in round_words('fos', ['-l---'], ['---s-'], dictionary=['slung'])] == ['slung'] # typed basil floss
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user