This was inspired by a now removed CS.SE question.
Given two non-empty input strings A and B, output the smallest distance from A to a palindrome that contains B as a substring. Distance is defined by the number of character replacements (Hamming distance).
- Sensible input: a palindrome exists. This means |A| ≥ |B|.
- A and B contain only lower ASCII characters, lowercase and uppercase are distinct (as are all other characters).
- If your language cannot deal with ASCII characters, you may use integers (or some other reasonable data type) as well, and you may choose to limit the range to 128 elements.
- You may take input from stdin, function arguments, command line arguments, etc.
- You may give the result on stdout, return value, etc.
- You do not need to give a working palindrome, the smallest distance to one is sufficient.
A B Output thilloaoyreot hello 4 (thelloaolleht) benjonson stack 9 (stackcats) neversaynever! odd 9 (neveroddoreven) ppcggcpp gg 0 (ppcggcpp) stars tat 1 (stats)
This is code golf, shortest code in bytes wins.