I started the foobar challenge a few days ago, and I am now at the first issue of the third step, and I have the challenge "Queue to do" . The problem is that I receive partial errors in the verification process. There are 10 test cases with 2 open cases and 8 hidden cases, and I had a problem with three hidden test cases.
This is the question:
Queue to do =========== You are almost ready to destroy the LAMBCHOP Domsday device, but the security checkpoints that protect the underlying systems of LAMBCHOP will be problematic. You managed to shoot one without triggering alarms, which is great! Except that as assistant commander Lambda, you learned that the checkpoints are about to be subject to automatic control, which means that your sabotage will be discovered and your cover stolen - unless you can fool the automatic control system. To deceive the system, you will have to write a program that will return the same amount of security check that the guards would have after controlling all the workers. Fortunately, Commander Lambda's desire for efficiency does not allow waiting times of several hours. Guards at checkpoints have therefore found ways to speed up the rate of transmission. Instead of checking every incoming worker, the guards check all people online while noting their security ID, and then let the line fill up. Once done, they go back to the line, this time leaving the last worker. They continue as well, leaving an extra worker on the line each time but saving the security IDs of those they check, until they jump the entire line, then they record the IDs of all the workers that they wrote down in a checksum and then leave for lunch. Fortunately, the orderly nature of the workers forces them to always align in a numerical order without gaps. For example, if the first operator of the line has ID 0 and the security checkpoint line contains three employees, the process will look like this: 0 1 2 / 3 4/5 6/7 8 where the checksum XOR (^) of the guards is 0 ^ 1 ^ 2 ^ 3 ^ 4 ^ 6 == 2. Similarly, if the first operator is identified by ID 17 and the checkpoint contains four, the process would look like this: 17 18 19 20 / 21 22 23/24 25 26/27 28 29/30 31 32 which produces the checksum 17 ^ 18 ^ 19 ^ 20 ^ 21 ^ 22 ^ 23 ^ 25 ^ 26 ^ 29 == 14. All worker IDs (including the first worker) are between 0 and 200,000,000 inclusive, and the checkpoint line will always have a minimum length of 1 worker. With this information, write a feature solution (start, length) that will cover the missing security checkpoint by generating the same checksum that the guards would normally submit before lunch. You just have time to find the ID of the first operator to check (start) and the length of the line (length) before the automatic review. Your program must therefore generate the appropriate checksum with these two values only. Languages ========= To provide a Java solution, edit Solution.java To provide a Python solution, edit solution.py Test case ========== Your code must pass the following tests. Note that it can also be run on hidden test cases not shown here. - Java case - Contribution: Solution.solution (0, 3) Exit: 2 Contribution: Solution.solution (17, 4) Exit: 14 - Python cases - Contribution: solution.solution (0, 3) Exit: 2 Contribution: solution.solution (17, 4) Exit: 14
I have tested my first code:
def solution (start, length): checksum = 0 for j in the beach (length): for i in the range (length-j): checksum ^ = (start + j * length + i) return the checksum
This code has returned three hidden test errors: Test # 5, # 6, # 9.
I have therefore tried to reconstruct the answer using a table.
def solution (start, length): checksum = 0 strin =  for j in the beach (length): for i in the range (length-j): strin.append (start + j * length + i) for i in strin: checksum ^ = i return the checksum
But now, this one throws me another failure of test case in test n ° 3, n ° 5, n ° 6, n ° 9
I would like to know why this difference in Test # 3 was made. And if possible, I would like to know what would be the cause of failures in other test cases (# 5, # 6, # 9).