The string
abaaba
Is a palindrome, meaning it doesn't change when it's reversed. However we can split it in half to make two palindromes
aba aba
We could also split it up this way:
a baab a
And all three of those are palindromes.
In fact there are only two ways to split the string into smaller strings such that none of them are palindromes:
abaa ba
ab aaba
Any other way we split this there is going to be at least one palidrome.
So we will say that this string has a palindromy number of 2. More generally a string's palindromy number is the number of ways to partition it into contiguous substrings such that none are a palindrome.
Your task will be to take a string as input and determine its palindromy number. Your answer must work correctly for inputs containing lowercase letters (a
-z
) along with any characters used in the source code of your program.
Scoring
Your answer will be scored by it's own palindromy number. With a lower score being the goal. In the case of ties the tie breaker is code-golf
This scoring does mean if you solve this in brainfuck you can get a lenguage answer with a primary score of 0. So if you are a lenguage enthusiast this is just code-golf.
Here's a program to score your code.
Test cases
a -> 0
aba -> 0
ababa -> 0
abababa -> 0
ffffffff -> 0
xyz -> 1
abaa -> 1
abaaa -> 1
abaaaaa -> 1
ooooooops -> 1
kvxb -> 2
kayak -> 2
abaaba -> 2
abaaaba -> 2
avakava -> 2
aaaaakykaaaaa -> 2
abaaaaba -> 3
ababab -> 4
abababab -> 8