# The Most Palindromy Code to Calculate Palindromy Numbers

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

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.

## 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

• Why doesn't the scoring code partition homology into length 1 partitions? E.g, shouldn't xyz be x yz and xy z , therefore 2? I feel like I'm missing something. Sep 2, 2021 at 3:25
• Is the answer that len 1 partitions are considered palindromes? Wouldn't that make xyz score 0? Or is no partition considered a partitioning? Sep 2, 2021 at 3:29
• @MVirts The scoring doesn't partition into strings of length 1 because they are always palindromes. Any partition with a length 1 string has a palindrome partition (the same is true of length 0 partitions). The 1 partition of xyz is indeed the trivial partition. xyz is not a palindrome so the partition of one element contains no palindromes. Sep 2, 2021 at 4:36

# Jelly, score 3, 755962277730462996760664 bytes

...‘‘‘‘ṃØJV


Try it online!

-5 score and +tons of bytes thanks to @ovs's idea.

...‘‘‘‘ part contains exactly 755962277730462996760660 copies of ‘ character, whose length encodes the following program in base 256:

# Jelly, 10 bytes

ɠŒṖŒḂ€€§¬S


Try it online!

The main code is a minor variation of Dude's answer (use of alternative built-ins, and input method changed to "a single line from stdin"), so here goes an explanation for the encoding part instead:

...‘‘‘‘ṃØJV    Main link (niladic).
...‘‘‘‘        Increment from zero 755..whatever..660 times
ṃØJ     Base decompress into Jelly's code page
V    Eval as a nilad (input is handled in the code itself)


The 3 non-palindromic partitions of ...aaaabcde are:

...aaaabcde
...aaaabc|de
...aaaab|cde

• I think you can replace ...““““”L with 383640471319762569300 times ‘
– ovs
Sep 3, 2021 at 9:48
• @ovs No, it errors since the program is a monad taking a string, and placing a leading 0 defeats the purpose of the encoding. EDIT: It might actually save some score if I change the input method. Sep 3, 2021 at 9:55
• Ah I see, I didn't include the input when I tried this. But could you make the encoded program read the input from stdin instead?
– ovs
Sep 3, 2021 at 10:01
• Yeah, I was thinking of exactly that. Sep 3, 2021 at 10:03
• You've turned Jelly into Lenguage. Well done. Sep 3, 2021 at 11:16

# Jelly, score 14 12, 9 bytes

ŒṖŒḂ€€§¬§


Try it online!

I thought this would be more of a baseline contender, but any modification I make to it to try to make it more palindromy only increases it instead. So, this is just the straight forward implementation.

-2 points thanks to xigoi

## How it works

ŒṖŒḂ€€§¬§ - Main link. Takes a string S on the left
ŒṖ        - Get all partitions of S
€    - Over each partition:
€     -   Over each substring in the partition:
ŒḂ      -     Is the substring a palindrome?
§   - Get the sum of each (counting how many substrings are palindromic)
¬  - Logical not. Map zeros to one, everything else to zero
§ - Sum, counting the zeros

• -2 by replacing ċ0 with ¬§: Try it online! Sep 2, 2021 at 19:17

# 05AB1E, score 18 (9 bytes)

.œεεÂÊ]PO


Explanation:

.œ      # Get all partitions of the (implicit) input-string
ε     # Map over each partition:
ε    #  Map over each part in this partition:
#   Check that it's NOT a palindrome by:
Â   #    Bifurcating it (short for Duplicate & Reverse copy)
Ê  #    And check that this reversed copy is not equal to the original string
]     # Close both nested maps
P    # Check for each partition whether no part was a palindrome
O   # Sum to get the amount of truthy values
# (after which the result is output implicitly)


I don't think this score nor byte-count can be improved, but I'd like to be proven wrong. Increasing the program size overall increases the score, otherwise Ê]PO to Q]O_O would have been a decent change with the palindrome O_O (this scores 22 at 10 bytes btw).

# Vyxal, 25 bytes, score 46368

LṄvṖ⁽JḭUƛvɾ:?f$•;'ƛḂ≠;A;L  Try it Online! -3 thanks to Aaron Miller. A big mess. Part of the code shamelessly stolen from Lyxal. L # Length ṄvṖ # All permutations of partitions ⁽Jḭ # Flatten by 1 level U # Uniquify ƛ ; # Foreach vɾ:?f$•          # Mold input to those pieces (see above link)
'     ;L # Number of values where
ƛḂ≠;A   # All aren't palindromes.

• 25 bytes Sep 1, 2021 at 13:32

# Stax, score 21 (9 bytes)

Æ₧ⁿ+Ü█>la


Run and debug it

the packed representation scores lesser, as shown in the tests.

Despite the existence of f!f and {{ in the unpacked version, the number of characters simply doubles the score.