Skip to content

Instantly share code, notes, and snippets.

@acoster
Created November 11, 2013 18:34
Show Gist options
  • Save acoster/7417994 to your computer and use it in GitHub Desktop.
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.
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