-
Notifications
You must be signed in to change notification settings - Fork 0
/
51.py
46 lines (40 loc) · 1.01 KB
/
51.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from tools.collections import mil_primes
import networkx as nx
import matplotlib.pyplot as plt
def hamming_distance(a,b):
a = str(a)
b = str(b)
if len(a) - len(b):
raise IndexError("Size of a and b don't match")
count = 0
for i, letter in enumerate(a):
if letter != b[i]:
count +=1
return count
def modified_hamming(a,b):
a = str(a)
b = str(b)
if len(a) - len(b):
raise IndexError("Size of a and b don't match")
count = 0
letters = []
for i, letter in enumerate(a):
if letter != b[i]:
count +=1
letters.append(b[i])
if len(set(letters)) == 1:
return count
return None
hundreds = mil_primes[mil_primes<1000]
hundreds = hundreds[hundreds > 99]
graph = nx.Graph()
for i in hundreds:
for j in hundreds:
distance = modified_hamming(i,j)
if distance:
graph.add_edge(i,j, weight=distance)
# nx.draw(graph)
# plt.show()
for i in hundreds:
print(graph[i])
break