Use that goodn't meme

12

2

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

Challenge

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.

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.

Examples

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 ...

The random guy

Posted 2018-05-30T12:03:17.600

Reputation: 1 262

1In the introduction, shouldn't I am small become I am bign't? – RedClover – 2018-05-30T14:20:59.287

4One point says "Input willl be [...] only with only . and ,". Another refers to "no-op". But that contains a "-". So is "-" allowed or not? – recursive – 2018-05-30T15:47:35.367

Should no n result in nn't or n't? – Kevin Cruijssen – 2018-05-31T06:48:23.837

no n sould result in n't because the 'word' n finish with a n. – The random guy – 2018-05-31T06:58:35.430

@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. – Yates – 2018-05-31T07:48:12.117

Answers

5

Retina, 86 70 65 bytes

T`-'`L
\bnot?\s+(?!not?\b)(\w+?)n?\b
$1n't
\bnot?\b
yesn't
T`L`-'

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

Try it online.

Explanation:

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

Kevin Cruijssen

Posted 2018-05-30T12:03:17.600

Reputation: 67 575

I think this shouldn't be the case

– Dead Possum – 2018-05-30T13:11:51.947

@DeadPossum Yeah, thought about that myself just yet and have already asked OP if "nn't" is possible in the input. – Kevin Cruijssen – 2018-05-30T13:12:37.737

1This is strange too – Dead Possum – 2018-05-30T13:14:31.737

@DeadPossum Ah, that's indeed a bug in my code. Will try to fix it. Thanks for noticing. – Kevin Cruijssen – 2018-05-30T13:15:13.810

no non should be non't . Don't hate me, I'm just interested in retina ._. – Dead Possum – 2018-05-30T13:40:47.663

@DeadPossum no non, no-op, and no nn't are some annoying edge cases.. But I think everything is fixed now (and my byte-count is doubled XD) – Kevin Cruijssen – 2018-05-30T14:11:58.993

1

I think I've got it down to 70 bytes.

– Neil – 2018-05-30T19:45:05.970

@Neil Thanks. Nice approach with the separated captured (n|(\w)). – Kevin Cruijssen – 2018-05-30T20:59:12.053

1L here is a shorthand for A-Z, saving 2 bytes over T`-'`AB and vice versa. – Neil – 2018-05-30T21:01:26.250

@Neil Ah ok, thanks for explaining. TIL. :) Not too familiar with Retina's builtins yet. – Kevin Cruijssen – 2018-05-30T21:09:08.690

@DeadPossum Punctuate it properly

– Stan Strum – 2018-05-30T21:38:56.663

@ovs It gives the incorrect result for "i am not ok, i have no plan and i have no gunn" (incorrect for any "not/no" followed by a word that ends in an "n"). – Kevin Cruijssen – 2018-05-31T06:15:58.713

@ovs Umm, all n't are now prepending the words instead of appending. EDIT: Changing the * to + seems to work though (I think). – Kevin Cruijssen – 2018-05-31T06:31:39.563

I really should have looked closer. I think this fails on no n now. The output should be n't but the program outputs nn't – ovs – 2018-05-31T06:39:03.900

@ovs Hmm, I figured it was supposed to be nn't. I'll ask OP to verify what to do with it. – Kevin Cruijssen – 2018-05-31T06:47:49.320

4

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.

TFeld

Posted 2018-05-30T12:03:17.600

Reputation: 19 246

2

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

l4m2

Posted 2018-05-30T12:03:17.600

Reputation: 5 985

2

Stax, 75 73 50 bytes

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

Run and debug it

recursive

Posted 2018-05-30T12:03:17.600

Reputation: 8 616

1

Japt, 72 bytes

F=_r"%bnot?%s+(?!not?%b)(%w+?)n?%b|%bnot?%b(?!['-])",@Y=Y||"yes"Y+"n't"}

Try it online!

Logern

Posted 2018-05-30T12:03:17.600

Reputation: 845

For "yes-no maybe-so", it produces "yes - mayben't - so". – recursive – 2018-05-30T18:07:18.247

0

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.

Kevin Cruijssen

Posted 2018-05-30T12:03:17.600

Reputation: 67 575