There is currently a meme on the internet that consist of taking a sentence, reverse the meaning and adding n't at the end. For example, I am small becomes I am talln't


For the sake of the challenge, we'll simplify this : Your task will be to detect whenever there is a negation in a sentence, and replace it with the 'positive' one with n't added at the end. There will be some tricky parts that will be explained in the rules.


  • You have to take a String as input, and return a String as output.
  • Input will be a sentence in lowercase, with only . and , as punctuation marks.
  • You have to replace any no <any_word> or not <any_word> with <any_word>n't.
  • no/not have to be a word and not a substring : you don't have to change anything in none of those
  • If the word already finish with a n, you have to replace n't with 't : no plan become plan't and not plann't
  • When no or not isn't followed by any word, a punctuation mark or another no/not, you have to replace it with yesn't.
  • compound words count as one word. so even if no-op contain the substring no, it doesn't contain the word no. So the result will be no-op and not -opn't.
  • You do not have to worry about grammar errors. For example, there is no way will result to there is wayn't.
  • No standard loopholes allowed.
  • This is , so the shortest code wins.

There are some examples, even if this challenge looks clearn't for now.


Input : i love codegolfing, but i do not like short programs. does this sentence makes sense ... of course no.
Output : i love codegolfing, but i do liken't short programs. does this sentence makes sense ... of course yesn't.

Input : you are not invited. get out.
Output : you are invitedn't. get out.

Input : i am not ok, i have no plan and i have no gunn
Output : i am okn't, i have plan't and i have gunn't

Input : oh no no no i refuse.
Output : oh yesn't yesn't in't refuse.

Input : oh no no no, i refuse.
Output : oh yesn't yesn't yesn't, i refuse.

Input : i cannot believe this, you can't codegolf.
Output : i cannot believe this, you can't codegolf.

Input : oh no ... he did it again.
Output : oh yesn't ... he did it again.

Input : nn't is not a word, kevin. so this is not nn't.
Output : nn't is an't word, kevin. so this is nn'tn't.

Input : is it not clearn't for everyone
Output : is this clearn'tn't for everyone

Input : this is non't sense ...
Output : this is non't sense ...

  • 1
    \$\begingroup\$ In the introduction, shouldn't I am small become I am bign't? \$\endgroup\$
    – RedClover
    Commented May 30, 2018 at 14:20
  • 4
    \$\begingroup\$ One point says "Input willl be [...] only with only . and ,". Another refers to "no-op". But that contains a "-". So is "-" allowed or not? \$\endgroup\$
    – recursive
    Commented May 30, 2018 at 15:47
  • \$\begingroup\$ Should no n result in nn't or n't? \$\endgroup\$ Commented May 31, 2018 at 6:48
  • \$\begingroup\$ no n sould result in n't because the 'word' n finish with a n. \$\endgroup\$ Commented May 31, 2018 at 6:58
  • \$\begingroup\$ @Soaku small, tall, big, tiny, large, long, short etc. are all used interchangeably. It doesn't really matter for the sake of the question. But the most logical antonym for small would be big, yes. \$\endgroup\$
    – Yates
    Commented May 31, 2018 at 7:48

6 Answers 6


Retina, 86 70 65 bytes


-16 bytes thanks to @Neil.
-5 bytes thanks to @ovs.

Try it online.


T`-'`L             # Replace all "-" with "A" and all "'" with "B" to store them

\bnot?             # Then replace the word "no" or "not",
 \s+               #  followed by 1 or more whitespaces,
 (?!not?\b)(\w+?)  #  followed by a word/letter that is not "not" or "no"
 n?\b              #  minus a single trailing "n" if there are any
$1                 # with: the word/letter
 n't               #  appended with "n't"

\bnot?\b           # Then replace any remaining loose "no" or "not"
yesn't             # with "yesn't"

T`L`-'             # And finally replace all "A" with "-" and all "B" with "'" again
  • \$\begingroup\$ I think this shouldn't be the case \$\endgroup\$ Commented May 30, 2018 at 13:11
  • \$\begingroup\$ @DeadPossum Yeah, thought about that myself just yet and have already asked OP if "nn't" is possible in the input. \$\endgroup\$ Commented May 30, 2018 at 13:12
  • 1
    \$\begingroup\$ This is strange too \$\endgroup\$ Commented May 30, 2018 at 13:14
  • 1
    \$\begingroup\$ I think I've got it down to 70 bytes. \$\endgroup\$
    – Neil
    Commented May 30, 2018 at 19:45
  • 1
    \$\begingroup\$ L here is a shorthand for A-Z, saving 2 bytes over T`-'`AB and vice versa. \$\endgroup\$
    – Neil
    Commented May 30, 2018 at 21:01

Python 2, 208 123 113 146 bytes

lambda s:re.sub(r"\bnot?\b(?!['-])(\s(?!not?(\b)(?!['-]))([\w'-]+))?",lambda m:(m.group(3)or"yes")+"n't"[(m.group(3)or'')[-1:]=='n':],s)
import re

Try it online!

Lost a bunch of bytes because of words ending in n't or n. Either or is shorter, but handling both was longer.


JavaScript (Node.js), 95 bytes

s=>s.replace(/\bnot?\b( (?!not?\b)(['\w-]*(\w)))?/g,(a,b,s,t)=>(s||'yes')+(t=='n'?'':'n')+"'t")

Try it online!

Thank Rick Hitchcock for 2 bytes


Stax, 75 73 50 bytes

ä§▀t9lJ₧5M#|+4╖¼├n▌ ·=┌«∙£╣▀K╖¥y▐▲·(■◄╙→á╣ó•ô╓╢Θ₧○

Run and debug it


Japt, 72 bytes


Try it online!

  • \$\begingroup\$ For "yes-no maybe-so", it produces "yes - mayben't - so". \$\endgroup\$
    – recursive
    Commented May 30, 2018 at 18:07

Java 8, 163 136 bytes

s->s.replaceAll("(^|[ ,.])not?(?= *([,.]|$|not?(?=$|[ ,.])))","$1yesn't").replaceAll("(^|[ ,.])not? ([\\w'-]+?)n?(?=$|[ ,.])","$1$2n't")

-27 bytes by creating a port of @recursive's Stax' answer.

Try it online.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.