Browse Source

adding a script to look for words with euclidean distance of 1.

master
Charles Reid 3 years ago
parent
commit
8e3af32e64
1 changed files with 28 additions and 0 deletions
  1. +28
    -0
      diff_by_one.py

+ 28
- 0
diff_by_one.py View File

@@ -0,0 +1,28 @@
"""
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))

Loading…
Cancel
Save