swetashetye / map-reduce-pattern Goto Github PK
View Code? Open in Web Editor NEWLet see an algorithm to calculate the control digit for a document number. The control digit algorithm goes like this. Here is the raw number. And for that number, we will calculate the control digit. And here is the entry point to the algorithm. The first step is to observe all digits of the number separately. Then every other digit is multiplied by 3. The resulting numbers are summed up. Finally, modulo 11 of the sum is taken. Modulo 11 operation yields results between 0 and 10 inclusive. Since we want to have a single digit as the result, the modular result of 10 sticks out. We have to deal with this special case separately. If the result is 10, it should be replaced by 1. Otherwise, the modular result is taken as the final result. That is how we are calculating the control digit for our document number.