forked from prakhar1989/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign.py
More file actions
23 lines (20 loc) · 763 Bytes
/
assign.py
File metadata and controls
23 lines (20 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os, sys
import operator
sys.path.append(os.path.join(os.getcwd(), os.path.pardir))
from graphs.graph import graph
from itertools import *
from union_find.unionfind import UnionFind
def ham_dist(e1, e2):
""" computes hamming distance between two strings e1 and e2 """
ne = operator.ne
return sum(imap(ne, e1, e2))
path = "clustering3.txt"
nodes = open(path).readlines()
uf = UnionFind()
# bitcount = {i: nodes[i].count('1') for i in range(len(nodes))}
# similar = [(bitcount[i]-9, ham_dist(nodes[i], nodes[0])) for i in range(1, len(nodes))]
# print nodes[1].count('1') - nodes[2].count('1')
# print hamdist(nodes[1], nodes[2])
for i in range(len(nodes)):
for j in range(i+1, len(nodes)):
print i, j, ham_dist(nodes[i], nodes[j])