Last active
June 7, 2024 10:38
-
-
Save benwrk/f767fa107891e1ce65df23b0b3f0f385 to your computer and use it in GitHub Desktop.
One-liner Thai National ID Card check digit calculator and validator
This file contains 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 calculate_id_card_check_digit(card_number: str) -> int: | |
return (11 - sum([(len(card_number) - i) * x for i, x in enumerate(map(lambda s: int(s), card_number[:-1]))]) % 11) % 10 | |
def validate_id_card_number_check_digit(card_number: str) -> bool: | |
return int(card_number[-1:]) == calculate_id_card_check_digit(card_number) |
This file contains 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 validate_id_card_number_check_digit(card_number: str) -> bool: | |
return int(card_number[-1:]) == (11 - sum([(len(card_number) - i) * x for i, x in enumerate(map(lambda s: int(s), card_number[:-1]))]) % 11) % 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment