Approximate Pattern Matching Problem: Find all approximate occurrences of a pattern in a string. Input: Strings Pattern and Text along with an integer d.
Output: All starting positions where Pattern appears as a substring of Text with at most d mismatches.
Output: All starting positions where Pattern appears as a substring of Text with at most d mismatches.
CODE CHALLENGE: Solve the Approximate Pattern Matching Problem.
Решено. Пример сходится. Квиз не принимается О_о
def hamdist(str1, str2):
diffs = 0
for ch1, ch2 in zip(str1, str2):
if ch1 != ch2:
diffs += 1
return diffs
def Approximate_Pattern(Pattern, Genome, d):
pos = []
for i in range(len(Genome) - len(Pattern) ):
if hamdist(Genome[i:i+len(Pattern)], Pattern) <= d:
pos.append(str(i))
return " ".join(pos)
print (Approximate_Pattern("ATTCTGGA", "CGCCCGAATCCAGAACGCATTCCCATATTTCGGGACCACTGGCCTCCACGGTACGGACGTCAATCAAAT", 3))
Немає коментарів:
Дописати коментар