Skip to content

Instantly share code, notes, and snippets.

@bbeck
Last active June 8, 2020 15:34
Show Gist options
  • Save bbeck/1a013d7dd3a48289b43cf429ad73df2e to your computer and use it in GitHub Desktop.
Save bbeck/1a013d7dd3a48289b43cf429ad73df2e to your computer and use it in GitHub Desktop.
import collections
import urllib
import sys
sides = [arg.upper() for arg in sys.argv[1:]]
letters = set("".join(sides))
word_list = urllib.urlopen("https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt")
# word_list = open("/usr/share/dict/words")
def is_letterbox_word(word, index={l: i for (i, side) in enumerate(sides) for l in side}):
if len(word) < 4:
return False
if not all(letter in letters for letter in word):
return False
last = -1
for letter in word:
if index[letter] == last:
return False
last = index[letter]
return True
index = collections.defaultdict(lambda: [])
for line in word_list:
word = line.strip().upper()
if not is_letterbox_word(word):
continue
index[word[0]].append(word)
for word1 in sorted(word for words in index.values() for word in words):
for word2 in sorted(index[word1[-1]]):
if letters == set(word1+word2):
print("%s > %s" % (word1, word2))
function perms() {
a=$1
b=$2
c=$3
echo "$a$a|$a$b|$a$c|$b$a|$b$b|$b$c|$c$a|$c$b|$c$c"
}
cat /usr/share/dict/words |
tr "[A-Z]" "[a-z]" |
grep -E "^[ramtuynohlip]+$" |
grep -v -E "$(perms r a m)" |
grep -v -E "$(perms t u y)" |
grep -v -E "$(perms h o n)" |
grep -v -E "$(perms l i p)" |
awk '(length($1) >= 3) { print length($1), $1 }' |
sort -rn |
awk '{print $2 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment