title: Can someone please explain XOR (for checksum) in Python 3
body: <p>I am working on an exercise for foo.bar and the basic idea is to take a list of integers and do some things to it to derive a specific subset of that list, then XOR (for a checksum) those values by means of this:</p>
  
  <pre><code>result = 0^1^2^3^4^6
  </code></pre>
  
  <p>Which equals 2</p>
  
  <p>Another example:</p>
  
  <pre><code>result2 = 17^18^19^20^21^22^23^25^26^29
  </code></pre>
  
  <p>Which equals 14</p>
  
  <p>I am not quite sure what is going on here and how these values(2, 14) are arrived at.</p>
  
  <p><strong>Actual Description of Problem from Foo.Bar</strong></p>
  
  <h1>> Queue To Do</h1>
  
  <p>You're almost ready to make your move to destroy the LAMBCHOP doomsday device, but the security checkpoints that guard the underlying systems of the LAMBCHOP are going to be a problem. You were able to take one down without tripping any alarms, which is great! Except that as Commander Lambda's assistant, you've learned that the checkpoints are about to come under automated review, which means that your sabotage will be discovered and your cover blown - unless you can trick the automated review system.</p>
  
  <p>To trick the system, you'll need to write a program to return the same security checksum that the guards would have after they would have checked all the workers through. Fortunately, Commander Lambda's desire for efficiency won't allow for hours-long lines, so the checkpoint guards have found ways to quicken the pass-through rate. Instead of checking each and every worker coming through, the guards instead go over everyone in line while noting their security IDs, then allow the line to fill back up. Once they've done that they go over the line again, this time leaving off the last worker. They continue doing this, leaving off one more worker from the line each time but recording the security IDs of those they do check, until they skip the entire line, at which point they XOR the IDs of all the workers they noted into a checksum and then take off for lunch. Fortunately, the workers' orderly nature causes them to always line up in numerical order without any gaps.</p>
  
  <p>For example, if the first worker in line has ID 0 and the security checkpoint line holds three workers, the process would look like this:</p>
  
  <p>0 1 2 /</p>
  
  <p>3 4 / 5</p>
  
  <p>6 / 7 8</p>
  
  <p>where the guards' XOR (^) checksum is 0^1^2^3^4^6 == 2.</p>
  
  <p>Likewise, if the first worker has ID 17 and the checkpoint holds four workers, the process would look like:</p>
  
  <p>17 18 19 20 /</p>
  
  <p>21 22 23 / 24</p>
  
  <p>25 26 / 27 28</p>
  
  <p>29 / 30 31 32</p>
  
  <p>which produces the checksum 17^18^19^20^21^22^23^25^26^29 == 14.</p>
  
  <p>All worker IDs (including the first worker) are between 0 and 2000000000 inclusive, and the checkpoint line will always be at least 1 worker long.</p>
  
  <p>With this information, write a function answer(start, length) that will cover for the missing security checkpoint by outputting the same checksum the guards would normally submit before lunch. You have just enough time to find out the ID of the first worker to be checked (start) and the length of the line (length) before the automatic review occurs, so your program must generate the proper checksum with just those two values.</p>
  
  <h1>Test cases</h1>
  
  <p>Inputs:</p>
  
  <pre><code>(int) start = 0
  
  (int) length = 3
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>(int) 2
  </code></pre>
  
  <p>Inputs:</p>
  
  <pre><code>(int) start = 17
  
  (int) length = 4
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>(int) 14
  </code></pre>