Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,27 @@
import urllib.request
from collections import Counter
GRID = """
N D E
O K G
E L W
"""
def getwords(url='http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'):
"Return lowercased words of 3 to 9 characters"
words = urllib.request.urlopen(url).read().decode().strip().lower().split()
return (w for w in words if 2 < len(w) < 10)
def solve(grid, dictionary):
gridcount = Counter(grid)
mid = grid[4]
return [word for word in dictionary
if mid in word and not (Counter(word) - gridcount)]
if __name__ == '__main__':
chars = ''.join(GRID.strip().lower().split())
found = solve(chars, dictionary=getwords())
print('\n'.join(found))

View file

@ -0,0 +1,70 @@
'''Word wheel'''
from os.path import expanduser
# gridWords :: [String] -> [String] -> [String]
def gridWords(grid):
'''The subset of words in ws which contain the
central letter of the grid, and can be completed
by single uses of some or all of the remaining
letters in the grid.
'''
def go(ws):
cs = ''.join(grid).lower()
wheel = sorted(cs)
wset = set(wheel)
mid = cs[4]
return [
w for w in ws
if 2 < len(w) and (mid in w) and (
all(c in wset for c in w)
) and wheelFit(wheel, w)
]
return go
# wheelFit :: String -> String -> Bool
def wheelFit(wheel, word):
'''True if a given word can be constructed
from (single uses of) some subset of
the letters in the wheel.
'''
def go(ws, cs):
return True if not cs else (
False if not ws else (
go(ws[1:], cs[1:]) if ws[0] == cs[0] else (
go(ws[1:], cs)
)
)
)
return go(wheel, sorted(word))
# -------------------------- TEST --------------------------
# main :: IO ()
def main():
'''Word wheel matches for a given grid in a copy of
http://wiki.puzzlers.org/pub/wordlists/unixdict.txt
'''
print('\n'.join(
gridWords(['NDE', 'OKG', 'ELW'])(
readFile('~/unixdict.txt').splitlines()
)
))
# ------------------------ GENERIC -------------------------
# readFile :: FilePath -> IO String
def readFile(fp):
'''The contents of any file at the path
derived by expanding any ~ in fp.
'''
with open(expanduser(fp), 'r', encoding='utf-8') as f:
return f.read()
# MAIN ---
if __name__ == '__main__':
main()