We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The S-1 translates the prisoner id to an equivalent index (since % effectively deals with indexes like 0..N-1). The M-1 handles the fact that the first prisoner to get a sweet is not counted when giving away sweets. Example, if you are giving away 1 sweet and you start at prisoner 37, it is 37 = (37 + 1 - 1) that should be warned. If you are giving away 2 sweets it is 38 = (37 + 2 - 1) that should be warned. And so on. The % N handles the wrapping around based on the index of the prisoners. And the + 1 brings us back to dealing with prisoner ID's instead of indicies.
Save the Prisoner!
You are viewing a single comment's thread. Return to all comments →
The
S-1translates the prisoner id to an equivalent index (since%effectively deals with indexes like0..N-1). TheM-1handles the fact that the first prisoner to get a sweet is not counted when giving away sweets. Example, if you are giving away 1 sweet and you start at prisoner 37, it is 37 = (37 + 1 - 1) that should be warned. If you are giving away 2 sweets it is 38 = (37 + 2 - 1) that should be warned. And so on. The% Nhandles the wrapping around based on the index of the prisoners. And the+ 1brings us back to dealing with prisoner ID's instead of indicies.