Last active
July 25, 2018 22:42
-
-
Save sharpobject/fd68e2206833a63a680c4b810d78b6e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local bylen = {} | |
for i=1,99 do bylen[i] = {} end | |
for word in io.lines("/usr/share/dict/words") do | |
if #word % 2 == 0 then | |
local bucket = bylen[#word] | |
bucket[#bucket+1] = word:lower() | |
end | |
end | |
for i=2,99,2 do | |
local prefixes = {} | |
local suffixes = {} | |
local joints = {} | |
local half = i/2 | |
for _,word in ipairs(bylen[i]) do | |
local prefix = word:sub(1,half) | |
local suffix = word:sub(half+1) | |
prefixes[prefix] = true | |
suffixes[suffix] = true | |
end | |
for prefix,_ in pairs(prefixes) do | |
if suffixes[prefix] then | |
joints[prefix] = {{},{}} | |
end | |
end | |
for _,word in ipairs(bylen[i]) do | |
local prefix = word:sub(1,half) | |
local suffix = word:sub(half+1) | |
if joints[prefix] then | |
joints[prefix][2][word] = true | |
end | |
if joints[suffix] then | |
joints[suffix][1][word] = true | |
end | |
end | |
for _,stuff in pairs(joints) do | |
for first, _ in pairs(stuff[1]) do | |
for second, _ in pairs(stuff[2]) do | |
print(first, second) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
removed dependencies