# Replace each ? in the expression with a digit or operator

In the following expression, replace each ? with either a digit or an operator:

8?5+??5-9?+3

so that it can evaluate to:

57883

• Which operators can be used? – xnor Mar 23 '15 at 4:06
• May we insert brackets "(" and ")" at arbitrary places in the expression? – Gamow Mar 23 '15 at 10:10
• Is 8!5 permissible as "eight factorial times five", or is it invalid? Is 5+--5 permissible as "five plus the negation of the negation of five" or is it invalid? Is 8.5 + 0.5 permissible, or is . not an operator? Is 005 a valid value, or are leading zeroes forbidden? Should the expression be evaluated left to right, or using PEMDAS rules, or something else? – Kevin Mar 23 '15 at 13:01
• @squeamishossifrage Going for a "pure math" solution, I got 8^5+7!5-90+3=57881. So close. – KSmarts Mar 23 '15 at 16:52
• I think this puzzle contains a mistake. It should be "+5" at the end. :) – KSmarts Mar 23 '15 at 17:07

I was thinking of "non-mathematical solution" that would have well-defined and accepted operators, and that telling which operators are acceptable, and one that came to my mind was that

evaluate here means "matches a regular expression", and the solution is for example 8*5+7[5-9]+3

• You got it, great job! :) Also accepted would be 8?5+7[5-9]+3 – pacoverflow Mar 23 '15 at 18:34
• But then the first ? would have not been replaced ;-) – Antti Haapala Mar 23 '15 at 18:48
• The wording of this question is misleading. A regular expression does not evaluate to a matching value, it validates a value. – Ian MacDonald Mar 23 '15 at 18:54
• Interesting puzzle, but those characters are metacharacters. – overloading Mar 23 '15 at 19:13
• @pacoverflow: No, the regex does not evaluate to many values. It validates many values. A regex is not a statement that evaluates to anything; it is a unary operator that takes an argument and produces a boolean result. – Ian MacDonald Mar 23 '15 at 20:00

I define the + operator as an operation that takes two somethings and returns 57883. Then I can insert whatever I want for the placeholders. The final +3 will give my the result.

Since you didn't originally clarify in the question that the operator must be a previously-defined and well-accepted operator, nor that an operator necessarily equates to a single character, my solution is:

8?5+??5-9?+3
885+475-9r+3

Where I have defined the following operators:
+ operator: (xyz)+(abc) : concatenate with inner-digit addition providing digit result: xy(z+a)bc.
- operator: xyz-y : delete digit providing digit result: xz.
r+ operator: xyzr+a : reverse the digits and concatenate without addition providing digit result: zyxa.

This works out as:

885+475-9r+3
88975-9r+3
8875r+3

57883

• interesting way of thinking, but the question contains only 1 space behind the 9, you've put a digit ànd an operator behind it – JBSregath Mar 23 '15 at 14:58
• Oh geez. I copied it from the question wrong when I started working on it. :S Gimmie a second. I'm sure there's a small tweak to make this still work. – Ian MacDonald Mar 23 '15 at 15:01
• I’m fine with - and r+ but if your + operator is acceptable, then mine is too :P – poke Mar 23 '15 at 15:38
• @IanMacDonald Oh no, my comment wasn’t really directed at you ;) (But yeah, you’re right, but still… how does a mathematician catch a lion? He gets in a cage and defines it as outside ;P) – poke Mar 23 '15 at 17:06
• @poke The mathematician recalls that he has seen a lion in captivity. He makes a claim that since someone has caught a lion, a solution exists QED. – blakeoft Mar 23 '15 at 18:52