Mathematics is fact. Programming is not In mathematics an exclamation mark ! often means factorial and it comes after the argument.
In programming an exclamation mark ! often means negation and it comes before the argument.
For this challenge we'll only apply these operations to zero and one.
Factorial
0! = 1
1! = 1

Negation
!0 = 1
!1 = 0

Take a string of zero or more !'s, followed by 0 or 1, followed by zero or more !'s (/!*[01]!*/).
For example, the input may be !!!0!!!! or !!!1 or !0!! or 0! or 1.
The !'s before the 0 or 1 are negations and the !'s after are factorials.
Factorial has higher precedence than negation so factorials are always applied first.
For example, !!!0!!!! truly means !!!(0!!!!), or better yet !(!(!((((0!)!)!)!))).
Output the resultant application of all the factorials and negations. The output will always be 0 or 1.
Test Cases
0 -&gt; 0
1 -&gt; 1
0! -&gt; 1
1! -&gt; 1
!0 -&gt; 1
!1 -&gt; 0
!0! -&gt; 0
!1! -&gt; 0
0!! -&gt; 1
1!! -&gt; 1
!!0 -&gt; 0
!!1 -&gt; 1
!0!! -&gt; 0
!!!1 -&gt; 0
!!!0!!!! -&gt; 0
!!!1!!!! -&gt; 0

The shortest code in bytes wins.
Mathematica, 25 17 bytes

Input[]/.!x_:&gt;1-x


Takes input from a user prompt. Assumes Mathematica's notebook environment for implicit printing. To make it a command-line script, wrap it in Print[...] or to make it an argumentless function (which then takes input from the prompt), append &amp;.

Mathematica has both of the required operators (with the required precedence), so we can just "eval" the input (which is done automatically by Input[]), but the logical negation operator doesn't work on integers (so it will remain unevaluated). If there's a !x left in the result, we replace it with 1-x.

A couple of fun facts about the evaluation:


Mathematica actually also has the double factorial operator !!, which computes n*(n-2)*(n-4)*..., but applied to 0 or 1 it still gives 1, so it doesn't matter that 0!!!!! will actually be parsed as ((0!!)!!)!.
Even though Mathematica leaves !0 and !1 unevaluated, it does know that ! is self-inverse, so it will automatically cancel all pairs of leading !. After the ToExpression we're always left with one of 0, 1, !0, !1.