• Alain Colmerauer designed the logic programming language Prolog. His goal was to create a programming language that is as intelligent as a two-year-old child. In order to prove that he had succeeded in his goal, he presented a Prolog program that answers "No" resourcefully for all inquiries.
?-

• (Of course he didn't.) Your task is to create a program that is more intelligent than Alain Colmerauer's program. This does not have to be in Prolog.

## Specifics

• If input ends with ? and has at least one ,, return text from the last , until before the last ?.

• Else, if input ends with ? return No.

• Else, return Yes.

## Rules

• No standard loopholes.
• Input/output will be taken via our standard input/output methods.
• Your program has to take at least 1 inquiry.
• You should output the processed inquiry.
• The Yes and No's are case-sensitive in the examples.
• You are guaranteed that if the input includes a ?, the input will only have one ? and it will always be the last character.
• The input will always be a phrase/sentence. This phrase/sentence will never only contain the characters , and ?, e.g. ,, ?, and ,? are not valid inputs. (Although submissions might implement it anyway, since the phrase/sentence is an empty string in these cases.)
• In addition, the input will never end with ,?.
• If there is whitespace immediately after the last , or immediately before the ?, they should be included in the output.

## Examples

Hmm. -> Yes
Alright, -> Yes
Ask me anything! -> Yes
Ask me a question, please! -> Yes
Are you okay? -> No
No? -> No
Hey,does this program work? -> does this program work

Quotes in the following test cases should not be outputted.
They are used as a delimiter here.

Okay, so this does work ? -> " so this does work "
Please, add, a, test, case, containing, multiple, commas? -> " commas"


## Scoring

This is , so shortest answer in bytes wins.

• Are we guaranteed that if the input includes a ?, there will only be one and it will always be the last character? – Shaggy Sep 16 '19 at 9:47
• Please add a test case containing multiple commas. – manatwork Sep 16 '19 at 10:19
• Accepting an answer early may discourage other users from posting new answers, because it kind of looks like the challenge is done. – Arnauld Sep 16 '19 at 11:58
• You are guaranteed that if the input includes a ?, the input will only have one ? and it will always be the last character. Therefore these test cases are unneccecary. – user85052 Sep 16 '19 at 14:28
• Is ends with ,? a valid input? – GammaFunction Sep 16 '19 at 16:11

# 05AB1E, 20 19 bytes

'?åi',¡”€–”0ǝθ¨ë”…Ü


-1 byte thanks to @Grimy.

Explanation:

'?åi          '# If the (implicit) input contains a "?":
',¡       '#  Split the (implicit) input on ","
”€–”    #  Push dictionary string "Not"
0ǝ  #  Insert it at the first position (index 0) in the list
θ       #  Then get the last item of the list
¨      #  And remove the last character
#  (either the "?" of the original input; or the "t" in "Not")
ë        # Else:
”…Ü     #  Push dictionary string "Yes"
# (after which the top of the stack is output implicitly as result)


See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”€–” is "Not" and ”…Ü is "Yes".

• 20 – Grimmy Sep 16 '19 at 11:10
• @Grimy Oh, smart thinking. Thanks! :) – Kevin Cruijssen Sep 16 '19 at 11:12

# Python 3, 62 bytes

lambda s:['Yes',*s[:-1].split(','),'No'][~(','in s)*('?'in s)]


Try it online!

The expression ~(','in s)*('?'in s) evaluates to 0 (i.e. 'Yes') if the string does not contain a '?', else -1 (i.e. 'No') if the string does not contain a ',', and otherwise -2 (i.e. the last comma-separated section of the string excluding the last character).

# JavaScript (ES6),  53  52 bytes

s=>(m=s.match(/(,?)([^,]*)\?/))?m[1]?m[2]:'No':'Yes'


Try it online!

### Commented

s =>                  // s = input string
( m = s.match(      // m is the result of matching in s:
//     +------------>    an optional comma
//     |     +------>    followed by a string containing no comma
//     |     |   +-->    followed by a question mark
//   <--><-----><>
/(,?)([^,]*)\?/
)) ?                // if m is not null:
m[1] ?            //   if the comma exists:
m[2]            //     output the string following it
:                 //   else:
'No'            //     output 'No'
:                   // else:
'Yes'             //   output 'Yes'

• Welp, was looking for a JS solution, ended up with something double this size. – The random guy Sep 16 '19 at 9:26

# Charcoal, 23 22 bytes

¿№θ?¿№θ,⁻⊟⪪θ,¦?¦No¦Yes


Try it online! Link is to verbose version of code. Edit: Saved 1 byte thanks to @KevinCruijssen. Explanation:

¿№θ?


Does the string contain any ?s?

¿№θ,


Does it contain any ,s?

⊟⪪θ,


Split the string on ,s and take the last.

⁻...?


Delete the ? and output the result.

No


If there are no ,s then output No.

Yes


If there are no ?s then output Yes.

• -1 changing Print(Join(Split(Pop(Split(q, ",")), "?"), w) to Print(Minus(Pop(Split(q, ",")), "?"); – Kevin Cruijssen Sep 16 '19 at 12:53
• @KevinCruijssen Thanks, I'd forgotten that Minus did that. Besides, I was feeling pleased with myself for saving two separators. – Neil Sep 16 '19 at 16:05

# Perl 5 + -plF/,|\?/, 25 bytes

$_=/\?$/?/,/?pop@F:No:Yes


Try it online!

# Pyth, 25 bytes

?qeQ\??}\,QPecQ\,"No""Yes


Try it online!

?q                          # if       ==
eQ\?                      #    Q[-1]    "?":
?}                    #   if     in
\,Q                 #      ","    Q:
cQ\,           #     return split(Q, ",")
e               #                         [-1] (last element)
P                #                             [:-1] (remove the trailing ?)
"No"       #   else: return "No"
"Yes"  # else: return "Yes" (last " implicit)


# Zsh, 51 bytes

<<<${${${1#*\?}:+Yes}:-${${${${1##*,}%$1}:-No}%\?}}


Try it online!

A byte can be saved if ends with,? and similar are invalid.

# Stax, 16 bytes

ëw‼◘╔╤▬n→ª▒¡Γ╟ï¿


Run and debug it

# Retina, 32 28 bytes

^'?KYes
.+,(.*)\?
$1 '?KNo  -4 bytes with tips from @Neil. Try it online. Explanation:  K # Replace any (implicit) input, which does ^ # NOT '? '# contain a "?" Yes # with "Yes" .+ # Match 1 or more characters , # followed by a comma .* # followed by zero or more characters, ( ) # (captured in capture group 1) \? # followed by a (trailing) "?"$1          # And replace it with just the match of capture group 1,
# (so everything between the last comma and trailing question mark)

K        # Replace any remaining string, which does
'?         '# contain a "?"
No      # with "No"

# (after which the result is output implicitly)

• Did you know that Retina 1's K stage has a built-in conditional? I didn't. It could probably save you a few bytes. – Neil Sep 16 '19 at 13:06
• @Neil I'm not sure how to chain the K and conditional & to be completely honest. I know how to use K with a regex to match like this, but how do I combine it with the conditional to mimic a ternary if-else for the Yes/No? – Kevin Cruijssen Sep 16 '19 at 13:38
• You don't need &, which is what surprised me, and you can just match on a string, or better still, a character, since you know that any ? must be at the end. – Neil Sep 16 '19 at 16:01
• @Neil So, like this? Which is also 32 bytes apparently. – Kevin Cruijssen Sep 16 '19 at 16:32
• Not quite; you're still matching on a regex, but you're allowed a string or character instead. – Neil Sep 16 '19 at 21:59

# IBM/Lotus Notes Formula, 79 bytes

@If(@Ends(i;"?");@If(@Contains(i;",");@Left(@RightBack(i;",");"?");"No");"Yes")


No TIO for Formula so...

# Python 3, 98 87 bytes

-9 bytes thanks to ElPedro

x=input();o="Yes"
if"?"==x[-1]:o=x[(x.rfind(",")+1):-1]if x.count(",")else"No"
print(o)


Try it online!

This has been solidly beaten by other answers, but I'm trying out golfing in Python a bit more. Advice is appreciated!

• You can use one print to avoid the assignment, then use a lambda since it's now just one statement, then shorten the inline if statements to a list indexing instead and then shorten the conditions to use in, then throw it all out because it's too close to an existing answer – Jo King Sep 16 '19 at 23:44
• A couple of golfs without changing your original approach to get it down to 87 Try it online! – ElPedro Sep 17 '19 at 7:32
• You can replace if x.count(",") with if~x.find(","), saving one byte. str.find evaluates to -1 if the string is not found. If you complement this with the unary operator, it results in 0 if and only if the substring is not present. Alternatively, you can replace it with if","in x  for 4 bytes fewer. – Jitse Sep 18 '19 at 7:23

# PHP, 58 bytes

<?=$argn[-1]=='?'?substr(strrchr($argn,','),1,-1)?:No:Yes;


Try it online!

# Red, 78 bytes

func[s][r:"Yes"parse s[to","copy t to"?"(r: last split t",")| to"?"(r:"No")]r]


Try it online!

# Perl 6, 40 bytes

{m/[\,(.*?)]*\?$/??$0.tail||"No"!!"Yes"}


Try it online!

# Gema, 34 characters

*,*\?=@subst{\*,=;$2} *\?=No *=Yes  Sample run: bash-5.0$ echo -n 'Hey,does this program work?' | gema '*,*\?=@subst{\*,=;\$2};*\?=No;*=Yes'
does this program work


# Japt, 23 bytes

ø'? ?Uq, hoinu¹Ìk'?:Y


Try it

# C# (Visual C# Interactive Compiler), 72 bytes

x=>x.Last()!=63?"Yes":x.Contains(',')?x.Split(',').Last().Trim('?'):"No"


Saved 2 bytes thanks to @someone

Try it online!

• SkipLast(1) -> Trim('?') for -??? bytes as far as I see (all my attempts to calculate the difference result in different numbers) – the default. Sep 17 '19 at 3:51

# Python 2, 6663 62 bytes

lambda i:("Yes",("No",i[i.rfind(",")+1:-1])[","in i])["?"in i]


Try it online!

-3 after spotting the updated clarification "the input will only have one ? and it will always be the last character."

-1 with thanks to @ChasBrown

Basically a port of my Lotus Notes answer. Curiously, the clarification noted above does not help the Notes answer because @Ends is 4 bytes cheaper than @Contains. Now if only there was an @In function...

• Save 1 byte by using rfind. – Chas Brown Sep 16 '19 at 19:19

# Jelly, 20 bytes

Ṗṣ”,Ṫ⁾NoḊ?Ɗ“Yes”i?”?


Try it online!

# C++ (gcc), 120 118 bytes

Function-like macro:

#include<string>
#define f(s)({int i{},j{};for(;s[i];)j=s[++i]-44?j:i;s[--i]-63?"Yes":j?std::string(s-~j,i+~j):"No";})
`

Try it online!

-2 bytes thanks to @ceilingcat