Пример #1
0
def cat(f):
    '''Main driver to solve this problem.'''
    return num_perfect_matching(ro.read_fafsa(f))
Пример #2
0
def motz(f):
    '''Main driver to solve this problem.'''
    return num_noncrossing_matching(ro.read_fafsa(f))
Пример #3
0
def mmch_dp(f):
    '''Main driver to solve this problem.'''
    return num_max_matching_dp(ro.read_fafsa(f))
Пример #4
0
import rosalind.rosutil as ro

def failure_array(s):
    n = len(s)
    k, i, p = 2, 0, [0] * (n + 1)
    p[0] = -1
    print 'n', n
    while k <= n:
        print 'k', k, 'i', i, 's[k-1]', s[k - 1]
        if s[k - 1] == s[i]:
            print 'Extend match to', s[k - i - 1:k], s[:i + 1]
            i += 1
            p[k] = i
            k += 1
        else: 
            if i > 0:
                print 'Back-track i from', i, 'to', p[i], 'match', s[:p[i]]
                i = p[i]  # Back-track to previous possible match
            else:
                print 'At beginning'
                k += 1  # Beginning of string, p[k] already initialized to 0 above
    return p[1:]

kmp = lambda f: ' '.join(repr(x) for x in failure_array(ro.read_fafsa(f)))

if __name__ == "__main__":
#    print kmp('rosalind_kmp.dat')
    print kmp('rosalind_kmp_sample.dat')
    # open('rosalind_kmp.out', 'wb').write(kmp('rosalind_kmp.dat') + '\n')