aliceyliang / letter-boxed-solver

30 stars 5 forks source link

Words later in `words_list` will override preceding words, leading to lesser answers #9

Open technocrat13 opened 4 months ago

technocrat13 commented 4 months ago

example game: 'mna, leu, xdw, pig'

one valid answer is 'EXUDING', 'GAWP', 'PALM' yet the function three_word_solution does not return this as an answer instead insists that 'EXUDING', 'GAWP', 'PALMING' is the only answer with 'GAWP' in it (I used a different word list but the error still stands)

the issue is caused due to the override that happens when multiple a and b instances satisfy the condition in the following dictionary creation:

    solutions = {a:b for a in candidates for b in word_list if set(a+b)==chars and a[-1]==b[0]}

to address this a list should be used as values created for every solution key, and update vals to handle the multiple possible answers:

    solutions = {}
        for a in candidates:
            for b in word_list:

                if set(a+b) == chars and a[-1] == b[0]:
                    if a not in solutions:
                        solutions[a] = []

                    solutions[a].append(b)

...

    vals = []
    for e in ext:
        if e[1] in solutions:
            for c in solutions[e[1]]:
                vals.append('-'.join([e[0], c]))

...

rest of the code remains the same, I tested this in a python notebook after extracting the solver function from the flask app, I will attach a pull request soon(tm) that will directly address this issue

technocrat13 commented 4 months ago

image

(left) current method answer count, (right) updated method answer count

with 19/06/2024's puzzle: 'veo, ims, cap, frn'