Skip to content

Instantly share code, notes, and snippets.

@les-peters
Created January 17, 2022 20:12
Show Gist options
  • Select an option

  • Save les-peters/f6fd4707b1ccde7622ae23fcdb892779 to your computer and use it in GitHub Desktop.

Select an option

Save les-peters/f6fd4707b1ccde7622ae23fcdb892779 to your computer and use it in GitHub Desktop.
Wordle
question = """
Using the rules of Wordle, given a guessWord and a solutionWord,
return a set of emojis returned from the guessWord.
Example:
let solutionWord = "fudge"
$ wordleGuess("reads", solutionWord)
$ "β¬›πŸŸ¨β¬›πŸŸ¨β¬›"
$ wordleGuess("lodge", solutionWord)
$ "β¬›β¬›πŸŸ©πŸŸ©πŸŸ©"
"""
def wordleGuess(guess, solution):
output = []
green_block = "\U0001F7E9"
yellow_block = "\U0001F7E8"
gray_block = "\U00002B1B"
# map solution characters
solution_chars = {}
place = 0
for char in solution:
if char not in solution_chars:
solution_chars[char] = {'count': 0, 'placement': []}
solution_chars[char]['count'] += 1
solution_chars[char]['placement'].append(place)
place += 1
# walk through guess, compare to solution
place = 0
for char in guess:
if not char in solution_chars:
output.append(gray_block)
elif place not in solution_chars[char]['placement']:
output.append(yellow_block)
else:
output.append(green_block)
place += 1
# print output
print(''.join(output))
solutionWord = "fudge"
wordleGuess("reads", solutionWord)
wordleGuess("lodge", solutionWord)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment