What is a percentage? How does one count one?
It does look like that you have two words that have same length and you count the positions that have identical characters. Lets take ABBA and BABA:
Two positions with identical characters.
If the two words are identical, then all positions are identical and the count equals length of the words. Identical words surely means 100% ?
Yes, you count something and then see that it is some fraction of something else. ABBA and BABA have 2/4, which equals 50/100, also known as 50%.
Like
lastchance said: count first and calculate later.
Furthermore, do not make your function to process all pairs. Make a simpler one that merely compares one "relative" to your "word". Then call that function with each "relative".
skaa mentions longest common subsequence. Real DNA can have mutation, insertion and deletion events. Counting identical characters from words handles only the mutation. Lets look at the two words again, but introduce
gaps
The "percentage" might actually be 3/5, i.e. 60% rather than the 50% of the first method.
For some reason I have a feeling that it is enough for you to do the first method.