Changes

From Biolecture.org

Minsu Kim/python/Rosalind

1,747 bytes added, 19:17, 12 December 2017
no edit summary
<p>&nbsp;</p>
 
<h2>Dynamic Program</h2>
 
<p>def maxvalue(a,b,c):<br />
&nbsp; &nbsp; a=a+5<br />
&nbsp; &nbsp; b=b-6<br />
&nbsp; &nbsp; c=c-6<br />
&nbsp; &nbsp; return max(a,b,c)<br />
def maxvalue2(a,b,c):<br />
&nbsp; &nbsp; a=a-2<br />
&nbsp; &nbsp; b=b-6<br />
&nbsp; &nbsp; c=c-6<br />
&nbsp; &nbsp; return max(a,b,c)</p>
 
<p>def compare(a,b):<br />
&nbsp; &nbsp; import numpy as np<br />
&nbsp; &nbsp; scoring = np.zeros([len(a)+1,len(b)+1])<br />
&nbsp; &nbsp; for i in range(0,len(a)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; scoring[i,0]=-6*i<br />
&nbsp; &nbsp; for j in range(0,len(b)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; scoring[0,j]=-6*j</p>
 
<p>&nbsp; &nbsp; for row in range(1,len(a)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; for column in range(1,len(b)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if b[column-1]==a[row-1]:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scoring[row,column] = maxvalue(scoring[row-1,column-1],scoring[row-1,column],scoring[row,column-1])<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if b[column-1]!=a[row-1]:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scoring[row,column] = maxvalue2(scoring[row-1,column-1],scoring[row-1,column],scoring[row,column-1])<br />
&nbsp; &nbsp; print(scoring)</p>
 
<p>&nbsp; &nbsp; list=[]<br />
&nbsp; &nbsp; for row in range(1,len(a)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; for column in range(1,len(b)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new=scoring[row,column]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list.append(new)<br />
&nbsp; &nbsp; mxv=max(list)<br />
&nbsp; &nbsp; print(mxv)</p>
 
<p><img alt="" src="/ckfinder/userfiles/images/bandicam%202017-12-12%2019-14-32-803.jpg" style="height:530px; width:640px" /></p>
Anonymous user

Navigation menu