In this project, my input will be 2 strings consisting of the characters A, G, C, and T. For instance:
and Count the number of positions at which 2 sequences (of equal length) differ.
truly appreciated .
inner_product works great for this kind of thing:
std::string s1 = "agatgctagatttcg";
std::string s2 = "agcctcccgatagcc";
int diffs = std::inner_product(s1.begin(), s1.end(), s2.begin(), 0,
std::cout << "The number of pairwise mismatches: " << diffs << '\n';
online live demo: http://ideone.com/SV4MK5
(although, depending on what you're studying you may be expected to write a loop, for example,
for(size_t n = 0; n < s1.size(); ++n)
, which increments a counter whenever
s1[n] != s2[n]
Last edited on
cubbi, you re the best!! thank you so much for the help.
hey, cubby ,
one more question,
how do I Allow the strings to be of different lengths. In this case, it works as follows:
These have a Hamming Distance of 3, because the "TAA" at the end is not matched in the 2nd string.
These have a Hamming Distance of 4: Positions 1,4,5,6 don't match.