Skip to content

Instantly share code, notes, and snippets.

@tarkatronic
Created May 9, 2024 15:02
Show Gist options
  • Save tarkatronic/97fbee67f4a96a57361e8484abaf95fa to your computer and use it in GitHub Desktop.
Save tarkatronic/97fbee67f4a96a57361e8484abaf95fa to your computer and use it in GitHub Desktop.
Python Spelling Bee Solver
from dataclasses import dataclass
from typing import TextIO
@dataclass
class Solver:
center_letter: str
all_letters: set[str]
dictionary: TextIO
def solve(self) -> list[str]:
candidates: list[str] = []
for word in self.dictionary.readlines():
word = word.strip()
if len(word) < 4:
continue
if word[0] not in self.all_letters:
continue
if self.center_letter not in word:
continue
if set(word) - self.all_letters:
continue
candidates.append(word)
return candidates
from dataclasses import dataclass
from typing import TextIO
@dataclass
class Solver:
center_letter: str
all_letters: set[str]
dictionary: TextIO
def solve(self) -> list[str]:
candidates: list[str] = []
for word in self.dictionary.readlines():
word = word.strip()
match word:
case word if len(word) < 4:
continue
case word if word[0] not in self.all_letters:
continue
case word if self.center_letter not in word:
continue
case word if set(word) - self.all_letters:
continue
case _:
candidates.append(word)
return candidates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment