Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (29 sloc) 1 KB
s=('UUAAGUAGCCGCGCCGGCUAUGCUAUAUGACGAUCGCGGCUCCGCGUAAAGAUGUCGAUC'
'GCAUUAGACGGCCCAAGUCUAGAUACGCUUACAUGUAGCAUUAAUAUGCGCGUACAUUCG'
'UAAAUAAUUGCUCGUACUAGCUCGAAGAAUUGCCUCGGUAUCGGGCAUCCGCCGGUGUCG'
'AAUCAUAUGCACGUCGGCGCACGUAAUGCAGUACAUGCGCUAUCUAGAAGCAUGCUAUAU'
'UUAAGCAU')
def candidates(s):
bases=['A','U','C','G']
comps=['U','A','G','C']
pair=dict(zip(bases,comps))
base_count=dict(zip(bases,[0,0,0,0]))
for i,x in enumerate(s):
base_count[x]+=1
if base_count['A']==base_count['U'] and base_count['G']==base_count['C'] and pair[x]==s[0]:
yield i
def catalan2(s,csave={}):
if len(s)==0:
return(1)
c=0
for x in candidates(s):
try:
c1=csave[s[1:x]]
except KeyError:
csave[s[1:x]]=catalan2(s[1:x],csave)
try:
c2=csave[s[x+1:]]
except KeyError:
csave[s[x+1:]]=catalan2(s[x+1:],csave)
c+=(csave[s[1:x]]*csave[s[x+1:]]) % 1000000
return(c)
You can’t perform that action at this time.