+ 2
count palindrome string
The palindromic score of a string is the number of errors(characters which do not match) when the string is read forwards and backwards. For example, the palindromic score of ‘fox’ is 2, because ‘fox’ and ‘xof’ differ by two characters. Write a function to take a string and return its palindromic score. //output aa=0 aabb=0 aaabbb=6 abcde=5 // please write return statement
6 odpowiedzi
+ 3
1. You didn't tag a language
2. Your output explanation doesn't make sense when compared to the description of the problem.
aabb = 0? Wouldn't this be 4
and
abcde = 5? Then how is fox 2 and not 3
3. Where is your attempt at solving the problem? Try it yourself first and post your code if you can't figure it out.
Hint: Take the original string and a reversed copy of the string and loop over the characters comparing them to each other, increment a counter when they differ.
0
sum([ 0 if a==b else 1 for a, b in zip(word,word[::-1]) ])
0
Jan Markus a kind of counter should be better
0
Frogged
You actually only need to go over the first half of the strings if you increment by 2 😉
0
ChaoticDawg
perfect!
0
Where I could find the answers for this