Mr. Mackey is a South Park character well-known for adding "m'kay" in everything he says.
Write a program or function that transforms a string of text into something Mr. Mackey would say.
M'kay placement
m'kay
has a random 50% chance of being added after the punctuations,
,.
,?
and!
. If that is the case, it will be followed by the exact same punctuation mark that preceeds it and preceeded by a space.For example, in the sentence
Test, test.
, there are two places wherem'kay
can be added: after the comma, and after the period, with a 50% chance at each place. Possible results would beTest, m'kay, test
. orTest, test. M'kay.
orTest, m'kay, test. M'kay.
.There must always be at least one
m'kay
added. Moreover, it cannot always be at the same place and each valid place wherem'kay
could be added must occur with equal probability. That is, you can't addm'kay
always at the end of the string if because of randomness you never added anym'kay
. If there is only onem'kay
, it must have the same probability of appearing in each valid position, even though its presence is enforced.If
m'kay
is after?
,.
or!
, them
must be uppercased.The number of
m
inm'kay
must be uniformely picked between 1 and 3. That is,m'kay
,mm'kay
andmmm'kay
are all possible choices, each with probability 0.33... If it must be uppercased (see above rule), allm
must be uppercased.
Inputs, outputs
Inputs are ASCII strings containing characters from ASCII Dec 32 (Space) to ASCII Dec 126 (Tilde
~
). There are no linebreaks in the input. You may assumed that any input will contain at least one of, . ? !
.You may assume that there are no
m'kay
or any of its variants in the input.Inputs may be taken from STDIN, function arguments, command line, or anything similar.
Output may be via STDOUT, a function return, or something similar.
Test cases
- Input:
Test.
Possible output: Test. M'kay.
- Input:
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.
Possible output: Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. MMM'kay. It's 100% free, mm'kay, no registration required.
- Input:
Drugs are bad, so, if you do drugs, you're bad, because drugs are bad. They can hurt your body, cause drugs are bad.
Possible output: Drugs are bad, m'kay, so, if you do drugs, you're bad, m'kay, because drugs are bad. They can hurt your body, m'kay, cause drugs are bad. M'kay.
- Input:
Do you understand? Really? Good!
Possible output: Do you understand? MM'kay? Really? Good! MMM'kay!
Scoring
This is code-golf, so the shortest code in bytes wins, m'kay?
M'kay
has a random 50% chance of being added after the punctuations ,, ., ? and !" seems to be incompatible with "There must always be at least onem'kay
added". Please clarify that \$\endgroup\$