# Problem
# Given two strings s and t of equal length, the Hamming distance between s and t, denoted dH(s,t),
# is the number of corresponding symbols that differ in s and t. See Figure 2.
# Given: Two DNA strings s and t of equal length (not exceeding 1 kbp).
# Return: The Hamming distance dH(s,t)
# Sample Dataset
# GAGCCTACTAACGGGAT
# CATCGTAATGACGGCCT
# Sample Output
# 7
# 这道题要求我们计算两个等长的 DNA 序列之间的 Hamming 距离,也就是这两个序列在同一位置上不同碱基的数量。
# 基础代码:
a = "GAGCCTACTAACGGGAT"
b = "CATCGTAATGACGGCCT"
m = 0
for i in range(len(a)):
if a[i] != b[i]:
m += 1
print(m)
# 用函数优化
def sum_base(a, b):
"""
计算两个等长的 DNA 序列之间的 Hamming 距离
"""
count = 0
for i in range(len(a)):
if a[i] != b[i]:
count += 1
return count
print(sum_base(a, b))