15
1
Today you will be doing another palindrome challenge!
So, your task today is to take a string, and determine the minimum amount of letters required to insert to turn it into a palindrome.
For example, let's take the string fishes
.
In this, case the best way would be to add h if
, so the result would be 3.
fishe s
h if
---------
fishehsif
Now let's try with codegolf
. Since there is a repeated o
, we can just do:
codeg o lf
fl ed c
-------------
flcodegedoclf
to get a result of 5.
Test cases
ppcg -> 2
codegolf -> 5
palindrome -> 9
stackexchange -> 8
programmingpuzzlesandcodegolf -> 20
1Related, with insertions only happening on the right. – xnor – 2016-11-05T01:29:28.743
2Wow, again, I had this exact challenge idea two days ago... but the scoring system would have been the length of your code + the output when its code is run through itself. (i.e. code is
ppcg
, score is 4 + 2 = 6) – ETHproductions – 2016-11-05T01:30:59.6075This is a nice challenge, but I'd prefer if challenges the same topic were more spaced out. There's been a lot of palindrome the last couple of days. – xnor – 2016-11-05T01:47:37.783
1It could be difficult to prove that a given program really finds the minimum amount of letters – edc65 – 2016-11-05T10:03:11.077