In [3]:
import forge
from data import warehouse
from puzzle.puzzlepedia import prod_config
prod_config.init()
trie = warehouse.get('/words/unigram/trie')
In [4]:
word = 'CHEAPSKATE'
targets = []
for x in reversed(range(2, round(len(word) / 2) + 1)):
targets.append((x, len(word) - x))
print(targets)
In [15]:
from data.seek_sets import chain_seek_set
def process(word, interesting=set(), required=None, length=None):
word = word.lower()
seek_set = chain_seek_set.ChainSeekSet(list(word), len(word))
if length:
lengths = [(length, len(word) - length)]
else:
lengths = targets(word)
for target in lengths:
if required and len(required) not in target:
continue
for result in walk(seek_set, [], target):
parts = result.split()
if required and required not in parts:
continue
a, b = parts
if a in interesting or b in interesting:
flag = '*'
else:
flag = ' '
print('%s %s (%s)' % (flag, result, word))
def targets(word):
targets = []
for x in reversed(range(2, round(len(word) / 2) + 1)):
targets.append((x, len(word) - x))
return targets
def walk(seek_set, acc, targets, pos=0):
if pos >= len(targets):
yield ' '.join(acc)
return
target = targets[pos]
seek_set.set_length(target)
for result, weight in trie.walk(seek_set, exact_match=True):
if weight < 5e4:
break
acc.append(result)
yield from walk(seek_set[result:], acc, targets, pos+1)
acc.pop()
In [7]:
process('ANTINRTLANOID', )
In [5]:
process('FREQUENCIES')
In [1]:
process('ANTINRELANOID')
In [30]:
process('LYINGDOWN')
In [31]:
process('NONJURY')
In [32]:
process('POWERPACK')
In [33]:
process('APPEALING')
In [34]:
process('ENAMORING')
In [35]:
process('AGREEABLE')
In [1]:
process('compared')
In [66]:
from nltk.corpus import wordnet
from data import warehouse
word_api = warehouse.get('/api/words')
In [93]:
extras = {'shy', 'red', 'gel', 'lest', 'ed'}
interesting = extras.union(fruits)
In [90]:
def syns(word, target_len):
word = word.lower()
process(word, interesting)
for w in word_api.synonyms(word):
if len(w) == target_len:
process(w, interesting)
In [92]:
syns('DISTENDED', 7)
In [64]:
def clean(s):
# Convert "dried_fruit.n.01" to "driedfruit".
return s.name().split('.')[0].replace('_', '')
def collect(acc, lemma):
s = wordnet.synset(lemma)
for f in s.hyponyms():
acc.add(clean(f))
fruits = set()
collect(fruits, 'edible_fruit.n.01')
collect(fruits, 'fruit.n.01')
fruits.remove('ear')
for fruit in sorted(fruits):
print(fruit)
In [58]:
from data import warehouse
anagram_index = warehouse.get('/words/unigram/anagram_index')
def scramble(bases, extra):
for base in bases:
search = base + extra
if search not in anagram_index:
continue
for result in anagram_index[base + extra]:
print(result, '=', base, '+', extra)
In [60]:
scramble(fruits, 'gel')
In [95]:
candidates = """
shy gel lest
""".split()
for w in candidates:
print(w)
scramble(fruits, w.lower())
In [100]:
candidates = """
entailing faltering filtering flagstone flowering forgetful galleries gargoyles gauntlets genealogy generally geniality genitalia gentleman gentlemen genuinely geologist ghastlier glaciated glassware gleanings gleefully glistened glorified glorifies glowering glutamate godliness graticule greyscale grovelled guardedly guerrilla guessable guideline guillemot heralding hexagonal ignorable illegally illegible impelling indulgent inelegant integrals irregular jestingly knowledge labelling lamenting languages largeness laughable leavening lecturing leeringly legalised legendary legionary legislate legstraps lengthier lessening lethargic lettering levelling licensing ligatured ligatures lightened lightness limelight lingering listening littering loitering longevity longitude loosening lumbering mellowing modelling molesting monologue neglected negligent neologism overlying panelling parleying pedalling pigtailed ploughers ploughmen privilege prologise prologize prologues prolonged ravelling realising realizing rebelling recalling reclining recoiling rectangle recycling refilling refluxing regretful regularly regulated regulates regulator releasing relegated relegates relieving religions religious relinking reloading repelling replacing replaying replugged resolving resulting retelling revealing revolting revolving rigmarole sacrilege salesgirl seedlings seemingly selecting shielding sidelight sightless signalled silencing singleton slaughter slavering slightest soldering spellings spillages squealing strangely strangled strangler strangles struggled struggles sugillate swellings tailgates telegrams telegraph trembling triangles trilogies unaligned underling unfeeling unplugged unsealing unveiling upwelling vegetable vestigial vigilance villagers welcoming wellbeing weltering wrestling yellowing
""".split()
for c in candidates:
process(c, interesting, required='gel')
In [102]:
import forge
from puzzle.puzzlepedia import puzzlepedia
puzzle = puzzlepedia.parse("""
mppgao
rn
ldp
abcdefghijklmnopqrstuvwxyz
i
mppgao
eem
arerpl
mppgao
nuaapi
eem
gncplv
abcdefghijklmnopqrstuvwxyz
rg
""", hint='acrostic')
In [18]:
process('herpameis')
In [124]:
print('\t'.join('O S I U B L E R A M I S H T E'.split()))
In [ ]: