Skip to main content

Wordle Helper

 I recently started playing Wordle, and while I love the game, I kind of got annoyed when I had guessed a couple of words and had only a few left, but had to go through the letters in my head one by one trying to figure out what was possible.  Brute-forcing letters like that is the job of a computer.... So I made a program to help me figure out possible letters more quickly.  

Basically, I took all the 5-letter English words, and knock them down based on what is known to be missing, what is known to be there, what is where, and what is not where.   I hope that someone else enjoys this program.  


#!/usr/bin/python3


''' 

This script reads in a dictioary of 5-letter english (supposedly) words (I AWK'd the five-letter words from a dictionary that may include non-real words), 

and prints out words that remain after the User Defined Variables are entered


Enter User Defined Variables with single quotes, separated by commas (i.e. 'o' or ['t','y'])

- First enter characters that are known in the correct position

- Next, enter characters that are known to be in the word (but not in the correct position)

- Next, enter characters that are known NOT to be in the word

- Last, Enter the characters that are known not to be in the correct position


'''


#dictionary_file = open('/home/john/Downloads/Five-Letter-English_Dictionary_Wordlist.txt', 'r')

dictionary_file = open('/home/john/valid-wordle-words.txt', 'r')

#dictionary_file = open('/home/john/Valid-Wordle-Words.txt', 'r')

Lines = dictionary_file.readlines()


############################################################

#####   Begin User Defined Variable Section   ##############


FirstIs = 's'

SecondIs = ''

ThirdIs = ''

FourthIs = ''

FifthIs = 'e'


IsInWord = ['n','i']

IsNotInWord = ['p','l','a','t','o','r']


FirstIsNot = ['']

SecondIsNot = ['n']

ThirdIsNot = ['i']

FourthIsNot = ['n']

FifthIsNot = ['']


#####  End User Defined Variable Section   ##############

#########################################################


TempFile = []

TempFile2 = []


############### Pocess the letters that are known to be in a place

###### Process First Letter   ##############

if FirstIs != '':     # Process First Letter

for Line in Lines:

if FirstIs == Line[0]:

TempFile.append(Line.strip())

else:

for Line in Lines:

TempFile.append(Line.strip())# Skip First Letter and move along


###### Process Second Letter   ##############

if SecondIs != '':     # Process Second Letter

for item in TempFile:

if SecondIs == item[1]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Third Letter   ##############

if ThirdIs != '':     # Process Third Letter

for item in TempFile:

if ThirdIs == item[2]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Fourth Letter   ##############

if FourthIs != '':     # Process Fourth Letter

for item in TempFile:

if FourthIs == item[3]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Fifth Letter   ##############

if FifthIs != '':     # Process Fifth Letter

for item in TempFile:

if FifthIs == item[4]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


############### Pocess the letters that are known NOT to be in a place

###### Process First Letter   ##############

if FirstIsNot != ['']:     # Process First Letter

for thing in FirstIsNot:

for item in TempFile:

if thing != item[0]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Second Letter   ##############

if SecondIsNot != ['']:     # Process Second Letter

for thing in SecondIsNot:

for item in TempFile:

if thing != item[1]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Third Letter   ##############

if ThirdIsNot != ['']:     # Process Third Letter

for thing in ThirdIsNot:

for item in TempFile:

if thing != item[2]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Fourth Letter   ##############

if FourthIsNot != ['']:     # Process Fourth Letter

for thing in FourthIsNot:

for item in TempFile:

if thing != item[3]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


###### Process Fifth Letter   ##############

if FifthIsNot != ['']:     # Process Fifth Letter

for thing in FifthIsNot:

for item in TempFile:

if thing != item[4]:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


#######  Process Known Inclusive Letters ######################

if IsInWord != ['']:

for useme in IsInWord:

for item in TempFile:

if useme in item:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


#######  Process Known Absent Letters ######################

if IsNotInWord != ['']:

for removeme in IsNotInWord:

for item in TempFile:

if removeme not in item:

TempFile2.append(item.strip())

TempFile = TempFile2

TempFile2 = []


#print("Here are the words left to choose from:")

#for item in TempFile:

# print(item.strip())   #  Print out the remaining words



##############################  Print Letters and how often they occur (Letter Frequency Table) #########################################


LetterStats = []


for item in TempFile:

for letter in item:

#print(letter)

if letter in LetterStats:

#print("letter: " + letter + " is in the list... incrimenting count")

letterindex = LetterStats.index(letter)

LetterStats[letterindex + 1]= LetterStats[letterindex + 1] +1

else:

#print("letter: " + letter + " is not in the list... adding....")

LetterStats.append(letter)

LetterStats.append(1)

#print("Here are the letter stats ", LetterStats)


SortedLetterList = []

#print("Length of LetterStats is: " + str(len(LetterStats)))

for i in range(0, len(LetterStats)-1,2):

#print(LetterStats[i])

SortedLetterList.append((LetterStats[i],int(LetterStats[i+1])))

#print("List before sorting: ")

#print(SortedList)


SortedLetterList.sort(key=lambda a: a[1], reverse=True)

print("Letter Frequency Table is: ")

print(SortedLetterList)

print(" ") #skip a linne



#############################   Next up is to give each word a score... If it has an e, it has the number of times e is seen in the remaining word list added to the score.... 

#############################   if it has a t, it has the number of times t is seen added to the score.

#############################   It then sorts the words from highest value to lowest... this will give the 'best' words to pick.

#############################   'best' means it will decrease the remaining words the fastest.  It is assumed that any word left is as likely as any other to be chosen by Wordle


ScoredWordList = []

for item1 in TempFile:  #Iterate through the words left

#print("Iterating through letters of word ", item1)

ScoredWordList.append(item1)

ScoredWordList.append(0)

for i in range(0, len(SortedLetterList)):

#print("Checking to see if ", SortedLetterList[i][0], " is in the word ", item1)

if SortedLetterList[i][0] in item1:  #The letter is in the word

#print(item2[0], "is in word ", item1, ". Adding: ", item2[1], " to the score of ", item1)

ScoredWordList[-1] = ScoredWordList[-1] +  SortedLetterList[i][1]  #  Add to the value of the word

#SortedWordList[:-1] = SortedWordList[:-1] + SortedLetterList[wordscore+1]


#print("This is the Word List with scores\n", ScoredWordList)


SortedScoredWordList = []

for i in range(0, len(ScoredWordList), 2):

SortedScoredWordList.append((ScoredWordList[i],int(ScoredWordList[i+1])))


SortedScoredWordList.sort(key=lambda a: a[1], reverse=True)


print("The best guessing order is:")

for i in SortedScoredWordList:

print(i)


Comments

Popular posts from this blog

2025 Tap And Map

 Tap And Map is back with new and improved installation instructions!   Here is an old video showing what TapAndMap is, for those who may not know: https://www.youtube.com/watch?v=gRfQzBjrhEE you'll notice that it's been a while since I've touched Tap And Map.   Because it's been so long since I built this, the old installation instructions would NEVER work to build it today (Feb 2025).   Plus, there was a Google Maps API bug that has troubled me all this time, as Google Maps would decide not to reload the page and I'd have to clear my history (lame).  Because my old code was built as an all-in-one method, so packets were sniffed, looked up, displayed, and logged, all in one large monolithic module, there was no easy means to troubleshoot.    So I've now decided to Sniff packets, lookup their IP information, and store the data in one script, and read that file, parse and publish html files in a separate module.  That allowed me to b...

HP c6180 Printer and Vista

Hp c6180 driver issues with Vista Home Premium My wife has a Vista Home Premium laptop, and the HP C6180 Photosmart printer keeps disappearing from her available printers.  The only way I've found to fix the problem is to reinstall all the HP software. When I do this, I have to download the (large..507M software from HP, or reinstall the printer (ONLY the printer, not the scanner) with the installation disk, as the drivers are not discovered with a "Windows Update" setting.  My guess is that is because HP doesn't like people to install only the printer driver, which would be easy, but they want folks to install all their crapware as well, so they are withholding the drivers from the on-line Microsoft printer database.  So keep your installation CD!  I've also found that unless I install everything on the CD or in the Full Version download (HP Customer Participation Program, HP Imaging Device functions, HP OCR SW, HP All-In-one SW, HP Photosm...

atftpd vs tftpd-hpa

Recently I was trying to tftp files from a Windows computer to a Kali box.   One version of Windows worked, but another didn't.    After much troubleshooting, here were my symptoms: I could tftp a file from-to any Kali box from-to another Kali box I could NOT tftp files to a specific Windows 7 box from any Kali box I could NOT tftp files to a Chrooted-Ubuntu-Chromebook box from a Kali box After MUCH troubleshooting, going through every setting in atftpd, it seemed like it literally was a client OS problem.  Different clients simply would not download files---unacceptable. Thus, I switched to tftpd-hpa.   To install: apt-get install tftpd-hpa files go to/come from /srv/tftp, but it needs to be a tftp user. Thus, I needed to: chroot -R /srv/tftp Also, if you want to be able to put files ON the tftp server (from a client), you need to modify /etc/default/tftpd-hpa: change "TFTP_OPTIONS="--secure"  to "TFTP_OPTIONS="--secure --create" ...