X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=riddle_definitions.md;h=da25f927c3eafc5f76b6ec1fc974e998a23d6f65;hb=a262c86b8d027e188b99e4ce57b77bae4411191d;hp=402fd949012cd5aa2de4a9c13acf8f41f86cde4c;hpb=5e5626bd52223307c5535d15668692e142e65d52;p=riddle-generator.git diff --git a/riddle_definitions.md b/riddle_definitions.md index 402fd94..da25f92 100644 --- a/riddle_definitions.md +++ b/riddle_definitions.md @@ -13,10 +13,6 @@ jupyter: name: python3 --- -# Definitions generally useful for the riddle solver - -While this file is here as a Markdown file, it's intended that Jupytext will save this file as a "percent" Python file, so that it can be imported by other notebooks here. - ```python import unicodedata import re @@ -28,8 +24,8 @@ import random ``` ```python -stop_words = set('my is in within lies and also always you will find the found'.split()) -negative_words = set('but not never neither nor'.split()) +stop_words = set('my is in within lies and also always you will find the found but'.split()) +negative_words = set('not never neither nor'.split()) ``` ```python @@ -111,20 +107,33 @@ def edit_distance(s: str, t: str) -> int: return len(t) if t == "": return len(s) - if s[-1] == t[-1]: + if s[0] == t[0]: cost = 0 else: cost = 1 res = min( - [ edit_distance(s[:-1], t)+1 - , edit_distance(s, t[:-1])+1 - , edit_distance(s[:-1], t[:-1]) + cost + [ edit_distance(s[1:], t) + 1 + , edit_distance(s, t[1:]) + 1 + , edit_distance(s[1:], t[1:]) + cost ]) return res ``` +```python +dictionary_neighbours = { + w: [o for o in dictionary + if edit_distance(w, o) <= 5 + if not set(w) <= set(o) + if not set(o) <= set(w)] + for w in dictionary} + +dictionary_neighbours = {w: ns + for w, ns in dictionary_neighbours.items() + if ns} +``` + ```python def collapse_riddle_clues(elems : Riddle) -> RiddleElems: """Combine the two parts of a riddle line into one element for solving.