Last active
May 30, 2016 12:33
-
-
Save mazlum/94f8bc510bd737c1591d3c75c196f384 to your computer and use it in GitHub Desktop.
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
| 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