Experiments with Knuth's 5,757 five letter words. https://charlesreid1.com/wiki/Five_Letter_Words
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
706 B

"""
diff_by_one.py
Donald Knuth
Art of Computer Programming
Volume 4 Facsimile 0
Exercise #28
Find pairs of SGB word vectors that differ by +/-1.
"""
from get_words import get_words
from euclidean_distance import euclidean_distance
if __name__=="__main__":
words = get_words()
#words = words[:1000]
k = 0
off_by_one = []
for i in range(len(words)):
for j in range(i,len(words)):
d = euclidean_distance(words[i],words[j])
if(abs(d)==1):
k += 1
off_by_one.append((words[i],words[j]))
print("{0:s}, {1:s}".format(words[i],words[j]))
print("{0:d} words have a Euclidean distance of +/-1.".format(k))