Skip to content

Instantly share code, notes, and snippets.

@mazlum
Last active May 30, 2016 12:33
Show Gist options
  • Select an option

  • Save mazlum/94f8bc510bd737c1591d3c75c196f384 to your computer and use it in GitHub Desktop.

Select an option

Save mazlum/94f8bc510bd737c1591d3c75c196f384 to your computer and use it in GitHub Desktop.
def tc_sum(i, k):
return int(i)+int(k)
def tc_checksum(tc_no):
if len(tc_no) < 11 or int(tc_no[10]) % 2 != 0 or int(tc_no[0]) == 0:
return False
single = reduce(tc_sum, [val for i, val in enumerate(tc_no[:9]) if i%2==0]) * 7
double = reduce(tc_sum, [val for i, val in enumerate(tc_no[:8]) if i%2!=0])
if not (single - double) % 10 == int(tc_no[9]):
return False
if not reduce(tc_sum, tc_no[:10]) % 10 == int(tc_no[10]):
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment