Skip to content

Instantly share code, notes, and snippets.

@bugbrekr
Last active July 23, 2024 15:00
Show Gist options
  • Save bugbrekr/cc0b493be944da4dbfcc7b45bd4f1749 to your computer and use it in GitHub Desktop.
Save bugbrekr/cc0b493be944da4dbfcc7b45bd4f1749 to your computer and use it in GitHub Desktop.
Simple and inefficient word unjumbler!
import sys
import time
import webbrowser
WORDS_FILE = 'words_alpha.txt'
num_words = sum(1 for line in open(WORDS_FILE))
def permutation(lst):
if len(lst) == 0:
return []
if len(lst) == 1:
return [lst]
l = []
for i in range(len(lst)):
m = lst[i]
remLst = lst[:i] + lst[i+1:]
for p in permutation(remLst):
l.append([m] + p)
return l
def solve(word):
word = word.lower()
letters = []
words = []
for letter in word:
letters.append(letter)
print('Permuting word, this may take a while...')
for peword in list(permutation(letters)):
pword = ''
for letter in peword:
pword += letter
words.append(pword)
print('\nDone Permuting. Found '+str(len(words))+' possible combinations.')
if len(word) >= 7:
time.sleep(3)
elif len(word) >= 2:
time.sleep(1)
print('Scanning '+str(num_words)+' words from dataset...')
valid_words = []
f = open(WORDS_FILE)
counter = 0
for i in range(num_words):
valid_word = f.readline()[:-1]
if valid_word[0] in word:
if len(valid_word) == len(word):
print('Found word with same length. Verifying word: '+valid_word)
if valid_word in words:
valid_words.append(valid_word)
counter +=1
webbrowser.open('https://google.com/search?original='+word+'&q='+valid_word)
print('Verification successful! Adding to list.')
else:
print('Word failed verification, continuing...')
f.close()
print('\nFound '+str(len(valid_words))+' words from dataset\n')
counter = 0
for word in valid_words:
counter +=1
print(str(counter)+': '+word)
while 1:
word = input('Jumbled word: ')
solve(word)
@bugbrekr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment