예제 #1
0
def jumble_solver(clue):
    clue = clue.lower()
    from words import Words
    w = Words()
    w.import_words()
    lengths = w.lengths
    matching_len_words = lengths[len(clue)]
    letters = dict()
    possible_words = list()
    possible = True
    for c in clue:
        if c in letters:
            letters[c] += 1
        else:
            letters[c] = 1
    for word in matching_len_words:
        for c, val in letters.items():
            if val == word.count(c):
                possible = True
            else:
                possible = False
                break
        if possible:
            possible_words.append(word)

    print('inside', possible_words)
    return possible_words
예제 #2
0
def cross_solver(clue):
    clue = clue.lower().strip('\n')
    #print(clue)
    w = Words()
    w.import_words()
    lengths = w.lengths
    matching_len_words = lengths[len(clue)]
    letters = dict()
    possible_words = list()
    possible = True

    given_letter_pos = []
    last_pos = 0
    for index, letter in enumerate(clue):
        if letter is not '?':
            given_letter_pos.append(index)
            last_pos = index

    #print(given_letter_pos)

    matching_words = []
    for word in matching_len_words:
        for pos in given_letter_pos:
            if word[pos] != clue[pos]:
                break
            elif (word[pos] == clue[pos]) and pos == last_pos:
                matching_words.append(word)

    return matching_words