51
6
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?
10+1, M'kay, but we need a Cartman challenge! – Level River St – 2015-07-28T16:43:37.983
16@steveverrill not sure the language in a Cartman challenge would be acceptable here sadly :P – Fatalize – 2015-07-28T16:45:43.743
1
I want to see an answer in Ook! MM'kay! But you'll probably want to use this algorithm for a pseudo-random number generator.
– mbomb007 – 2015-07-28T20:04:24.9973@Fatalize: It's all Kyle's mom's fault. – marinus – 2015-07-28T20:08:32.110
4"
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 – Luis Mendo – 2015-07-28T23:58:10.300Does this "The number of m in m'kay must be uniformely picked between 1 and 3... Mean that all
M'kay
's in a sentence should have the same number ofM
's? Because your example outputs for "Programming puzzles...." and "Do you understand...." do not appear to follow this rule. Please clarify what you mean. – CBRF23 – 2015-07-29T03:57:39.600Is a capitalized
M'kay
valid at the start of the string? – Winny – 2015-07-29T04:41:44.550@Winny No, it's not valid. – Fatalize – 2015-07-29T06:08:36.520
@LuisMendo I don't see how it can be clearer. There's a 50% chance for each
m'kay
but at least one must be enforced regardless of the 50% chance. – Fatalize – 2015-07-29T06:12:19.020@CBRF23 No, it, the number of
m
is independant between eachm'kay
. – Fatalize – 2015-07-29T06:13:06.583In the first test case, shouldn't the program always produce the same output, given that at least one m'kay is required and they can only appear after punctuation? ie, *"Only possible output: Test. M'kay." – Adam Davis – 2015-07-29T19:58:56.740
@AdamDavis The
m'kay
will indeed always be there but the number of M's can vary from one to three – Fatalize – 2015-07-29T19:59:42.5401@Fatalize Mmm'kay! – Adam Davis – 2015-07-29T20:00:17.730
Can the input include
m'kay
, and if yes, would returning the input as the output (i.e. it includes at least onem'kay
but did not add any) pass? I saw at least one answer that checked for the presence ofm'kay
to determine whether it had randomly added at least one, but that approach would fail if the input started with at least onem'kay
. – KRyan – 2015-07-30T18:12:27.913@KRyan It's ok to assume that there are no
m'kay
in the input. – Fatalize – 2015-07-30T19:01:18.270@Fatalize OK, then that should probably be in the question. – KRyan – 2015-07-30T19:02:34.797
1A way of demonstrating the incompatibility mentioned by @LuisMendo would be to consider a string with only one punctuation mark. – Cameron Martin – 2015-08-03T18:28:14.367