Created
November 11, 2013 18:34
-
-
Save acoster/7417994 to your computer and use it in GitHub Desktop.
I miscopied the tracking number for my passport's return envelope, and forgot the last digit. Luckily the Royal Mail publishes how to calculate their checksums.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import operator | |
def calculate_checksum(number): | |
digits = [int(x) for x in number] | |
return 11 - (sum(itertools.imap(operator.mul, digits, [8, 6, 4, 2, 3, 5, 9, 7])) % 11) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment