Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (31 sloc) 938 Bytes
import numpy as np
patterns=[]
with open("rosalind_itwv.txt","rU") as f:
base=f.readline().strip()
for line in f:
patterns.append(line.strip())
n=len(base)
plen=len(patterns)
m=np.zeros((plen,plen),dtype=int)
def test(x,y,base,i):
if x=='':
return base[i:].startswith(y)
elif y=='':
return base[i:].startswith(x)
if (x[0]==base[i] and test(x[1:],y,base,i+1)):
return True
if (y[0]==base[i] and test(x,y[1:],base,i+1)):
return True
return False
for i in xrange(plen):
for j in xrange(i,plen):
for k in xrange(n-len(patterns[i])-len(patterns[j])+1):
if test(patterns[i],patterns[j],base,k):
m[i,j]=1
m[j,i]=1
break
with open("itwv.out","w") as f:
for i in range(plen):
for j in range(plen):
f.write( str(m[i,j])+' ')
f.write('\n')
You can’t perform that action at this time.