# 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 -> 0
1 -> 1
0! -> 1
1! -> 1
!0 -> 1
!1 -> 0
!0! -> 0
!1! -> 0
0!! -> 1
1!! -> 1
!!0 -> 0
!!1 -> 1
!0!! -> 0
!!!1 -> 0
!!!0!!!! -> 0
!!!1!!!! -> 0


The shortest code in bytes wins.

• But 0!=1!, so what's the point of handling multiple factorials? Feb 6, 2017 at 9:22
• @boboquack Because that's the challenge. Feb 6, 2017 at 9:24
• <?='1'; ... correct 75% of the time in php. Feb 6, 2017 at 17:17
• I may be wrong here but can't any number with any factorials after it simply be removed and replaced with 1? Like 0!!!! = 1!! = 0!!!!!!!! = 1!!! = 1! = 0! = 1 etc Feb 6, 2017 at 22:33
• @AlbertRenshaw That is correct. Feb 6, 2017 at 22:54

# Wren, 50 bytes

Fn.new{|a|(a[-1]=="0"?1:0)^a.trimEnd("!").count%2}


Try it online!

# Julia 0.7, 28 bytes

~s=s[1]<'0'?!~s[2:end]:s>"0"


Try it online!

called with ~"!!0!", returns true or false

ungolfed:

function f(s)
if s[1] == '!'
return !f(s[2:end])
else
return s>"0"
end
end


s>"0" is false only for s=="0"

# Lexurgy, 47 bytes

f:
{\0,\1} \!+=>\1
e:
\!\!=>*
g:
\! {\0,\1}=>* {\1,\0}


### Explanation

# strip factorials
f:
{\0,\1} \!+=>\1

# !!X = X
e:
\!\!=>*

# apply !
g:
\! {\0,\1}=>* {\1,\0}


# YASEPL, 81 bytes

=1'=s®1=i1!m¥i,1ſ""}7,exclamation,2!i+}2,s2!1±m!3¥1,1®3}2,1,3!m\$3!3¥0,1®3+m%<
`
• Could you provide a link to the language, or an online interpreter where people could test this? Mar 27 at 3:03
• Whoopsies! my mistake, I'll link it. I'm working on an online interpreter right now for it too! github.com/madeforlosers/YASEPL-esolang Mar 27 at 17:25