title: XOR of three values
body: <p>What is the simplest way to do a three-way exclusive OR?</p>
  
  <p>In other words, I have three values, and I want a statement that evaluates to true IFF only <em>one</em> of the three values is true.</p>
  
  <p>So far, this is what I've come up with:</p>
  
  <p>((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))</p>
  
  <p>Is there something simpler to do the same thing?</p>
  
  <hr>
  
  <p>Here's the proof that the above accomplishes the task:</p>
  
  <pre><code>a = true; b = true; c = true
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; false
  
  a = true; b = true; c = false
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; false
  
  a = true; b = false; c = true
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; false
  
  a = true; b = false; c = false
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; true
  
  a = false; b = true; c = true
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; false
  
  a = false; b = true; c = false
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; true
  
  a = false; b = false; c = true
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; true
  
  a = false; b = false; c = false
  ((a ^ b) &amp;&amp; (a ^ c) &amp;&amp; !(b &amp;&amp; c)) || ((b ^ a) &amp;&amp; (b ^ c) &amp;&amp; !(a &amp;&amp; c)) || ((c ^ a) &amp;&amp; (c ^ b) &amp;&amp; !(a &amp;&amp; b))
  =&gt; false
  </code></pre>