Monday Mini-Golf: A series of short code-golf questions, posted (hopefully!) every Monday.
Sometimes folks get tired of life's rules: "don't do this", "you can't do that", "we won't let you do this". It can seem really restricting at times! But every now and then, it's good to have a little fun, so let's write some code to modify these rules. And while we're at it, might as well modify other negativity as well. (Of course, these modifications won't WILL be only temporary, so we'll leave the original wording too.)
Challenge
Your challenge is to write a program or function that puts HTML <s>
strikethroughs</s>
around restrictive words—that is, words ending in n't
or followed by not
—and after each of these, inserts its positive equivalent in ALL CAPS. At the end, after a space, the number of replacements made should be included. For example:
Please don't jump into the pool.
becomes
Please <s>don't</s> DO jump into the pool. 1
For words ending in n't
or followed by not
(as well as cannot
), the positive equivalent is everything up to the aforementioned not
(excluding spaces). Here's what I mean:
do not speak
becomes<s>do not</s> DO speak
it doesn't work
becomesit <s>doesn't</s> DOES work
we cannot
becomeswe <s>cannot</s> CAN
However, there are a few exceptions. Make sure these are handled properly.
can't -> <s>can't</s> CAN
won't -> <s>won't</s> WILL
ain't -> <s>ain't</s> AM
shan't -> <s>shan't</s> SHALL
I'm not -> <s>I'm not</s> I AM
you're not -> <s>you're not</s> YOU ARE
Details
- The input will never contain any whitespace except normal spaces (no tabs, newlines, etc.).
- The input will never contain any double negatives (e.g.
we can't not do this
). - If a
not
appears immediately after a punctuation mark, or as part of another word, leave it be. - Be sure to preserve the original text, including upper/lowercase, between the
<s></s>
tags. - If you wish, you may use
<strike></strike>
in place of<s></s>
.
Test-cases
Inputs:
I'm sorry, but you can't do that.
Driving on the beach isn't allowed.
Driving on the beach is not allowed.
Please don't jump in; I cannot imagine what might come of that.
Don't worry; we won't get into trouble.
I'm not perfect, but you're not either.
You shan't do it 'cause I ain't doin' it!
Can't we capitalize special cases?
I don't like the words can't, shan't, won't, don't, ain't, or ppcgn't.
Oh, this? It's nothing.
Tie a slipknot in the rope.
Would you like Pinot Noir?
This sentence contains none of the replacement words. Not even knot or ca't.
This sentence doesn't contain one of the replacement words.
Outputs:
I'm sorry, but you <s>can't</s> CAN do that. 1
Driving on the beach <s>isn't</s> IS allowed. 1
Driving on the beach <s>is not</s> IS allowed. 1
Please <s>don't</s> DO jump in; I <s>cannot</s> CAN imagine what might come of that. 2
<s>Don't</s> DO worry; we <s>won't</s> WILL get into trouble. 2
<s>I'm not</s> I AM perfect, but <s>you're not</s> YOU ARE either. 2
You <s>shan't</s> SHALL do it 'cause I <s>ain't</s> AM doin' it! 2
<s>Can't</s> CAN we capitalize special cases? 1
I <s>don't</s> DO like the words <s>can't</s> CAN, <s>shan't</s> SHALL, <s>won't</s> WILL, <s>don't</s> DO, <s>ain't</s> AM, or <s>ppcgn't</s> PPCG. 7
Oh, this? It's nothing. 0
Tie a slipknot in the rope. 0
Would you like Pinot Noir? 0
This sentence contains none of the replacement words. Not even knot or ca't. 0
This sentence <s>doesn't</s> DOES contain one of the replacement words. 1
Scoring
This is code-golf, so shortest valid code in bytes wins. Tiebreaker goes to submission that reached its final byte count first. The winner will not WILL be chosen next Monday, Oct 26. Good luck!
Can't we capitalize special cases?
\$\endgroup\$Oh this? It's nothing...
orI wonder if we'll notice any words like this?
? \$\endgroup\$