To be very honest, I don’t really understand your approach. Are you making temporal shiftings to then that be compared to the next triad?
The problem with that approach is that your conditionals aren’t actually making anything. Was that on purpose?
But the main problem is that in your else statement, you are counting several times one corner case that should be counted only once:
Say, this:
“aaabaaabaaa”
Everytime it gets to any of the 3 substrings “aaa” it gets counted once. But that is wrong because you should count the different strings, and those shifts make the same string, so that can’t be counted more than once.
You have 3 base cases to be considered:
When you have the 3 characters as the same
2 out of 3 are the same
All are different.
These are:
If all the 3 characters are the same, then you get the original string. That can happen more than once as the example above. So let’s flag that as “original_string”.
If 2 out of 3 are the same, then there’s a risk you can have the same string in other shiftings. How to know? Let’s think of this corner case:
“aaba”
You can get “abaa” 2 times
By knowing that 0, 1 and 3 are the same, but 2 is different, you know that it is going to be a repetition. Try this out in a notebook.
All different characters make a unique new strings.