Created
January 17, 2022 20:12
-
-
Save les-peters/f6fd4707b1ccde7622ae23fcdb892779 to your computer and use it in GitHub Desktop.
Wordle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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