Skip to content

Instantly share code, notes, and snippets.

@WorryingWonton
Last active July 12, 2023 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WorryingWonton/1a97336b86aaa724c0ebe8c3d254cff5 to your computer and use it in GitHub Desktop.
Save WorryingWonton/1a97336b86aaa724c0ebe8c3d254cff5 to your computer and use it in GitHub Desktop.
Program to cheat at the iOS game Word Laces
from itertools import permutations
class LaceWords:
def __init__(self, dictionary=None, interface=None):
self.dictionary = dictionary
if not dictionary:
self.dictionary = 'scrabble_2020_dict'
self.interface = interface
if not self.interface:
self.interface = LaceWordsInterface
self.words = self.open_dictionary()
def open_dictionary(self):
return [word.lower() for word in open(self.dictionary, 'r').read().split('\n')]
def cheat_at_word_laces(self):
while True:
letter_blocks = self.interface.request_letter_blocks()
if 'stop_session' in letter_blocks:
break
word_candidates = self.generate_letter_combos(letter_blocks)
words = self.find_if_combo_is_word(word_candidates)
self.interface.print_words(words)
def generate_letter_combos(self, letter_blocks):
word_candidates = []
word_len = 1
while word_len <= len(letter_blocks):
word_candidates += [''.join(x) for x in permutations(letter_blocks, r=word_len)]
word_len += 1
return set(word_candidates)
def find_if_combo_is_word(self, word_candidates):
return sorted(set(self.words) & word_candidates, key=lambda x: len(x))
class LaceWordsInterface:
@staticmethod
def request_letter_blocks():
letter_blocks = input('Enter all letter blocks separated by a space: ')
return [block.lower() for block in letter_blocks.split()]
@staticmethod
def print_words(words):
print('\n'.join(words))
if __name__ == '__main__':
LaceWords().cheat_at_word_laces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment