Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168744
Image: ubuntu2004
from fractions import Fraction def Index_string(a,b, L): k_0=0; k_1 = 0; Ind=0 ; for i in range(0,len(L)): if L[i] == a: k_0= k_0 + 1 for j in range(0,len(L)): if L[j] == b: if j < i: Ind = Ind-1 if j > i: Ind = Ind+1 k_1 = len(L) - k_0 return Fraction(Ind, 2*k_0*k_1) #[k_0,k_1,Ind,Ind/(2*k_0*k_1)] def Curvature(a,b,c,L): # curvature of 3-character word. Use: # Curvarure(first chararacter , second character, third character, word ); Lab =""; Lac=""; Lbc=""; for i in range(0,len(L)): if L[i] == a: Lab=Lab+L[i]; Lac=Lac+L[i] if L[i] == b: Lab=Lab+L[i]; Lbc=Lbc+L[i] if L[i] == c: Lac=Lac+L[i]; Lbc=Lbc+L[i] return Index_string(a,b,Lab)-Index_string(a,c,Lac)+Index_string(b,c,Lbc)
print Curvature("a","p","s","papaspaspsa") print Curvature("s","e","l","selllesseels") print Curvature("l","g","u","lguguglu")
-1/24 1/16 0