Censors are a common tool used on the interwebs. But they often censor too much of the word, and thus make the cursing ambiguous to the reader. And sometimes they don't censor enough, so the words still remain offending. Your task is to fix that.
Write a program/function/whatever that takes two lists and a string. The first list will be the dictionary of all words in your language like:
["hello", "goodbye", "belgium", "offensive", "jumping", "hypercool"]. The next will be subset of the first list containing all of the offensive words in the language:
["belgium", "offensive"]. The words in these lists are guaranteed to contain only lowercase letters of the alphabet.
The string is the phrase you will have to censor. It will be made of words from the dictionary, separated by spaces:
"Goodbye offensive belgium"
The return value will be that phrase censored. However, you have to censor in a certain way. Specifically, for each word in the offensive list, you have to censor as many letters as possible while remaining completely unambiguous in the main dictionary. So here it would be:
Goodbye o******** b******.
- Your code has to interpret the words case-insensitively, but return with the initial capitalization.
- If there are multiple optimal answers, pick any of them.
- If unambiguous censoring is impossible, censor a single letter that has the least number of other possible interpretations (If multiple are possible, again, its your choice).
["hello", "goodbye", "belgium", "offensive", "jumping", "hypercool"] ["belgium", "offensive"] "Goodbye offensive belgium" -> "Goodbye o******** b******" ["word"] ["word"] "word" -> "****" ["hot", "hat", "bat", "had"] ["hat"] "hat" -> "*at" or "h*t" or "ha*" https://gist.github.com/deekayen/4148741 ["quart"] "I am a quart" -> "I am a q**r*"
This is code-golf so shortest d*mn code in bytes wins!
P.S. Anyone caught the reference with belgium? ;P