Last active
January 6, 2016 14:37
-
-
Save LuisRBarreras/de211a9a22c65b9d4b37 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
from functools import reduce | |
import sys | |
def check_credict_card(card_numbers): | |
singles = reduce(lambda x,y: x+y, [x for x in card_numbers[1::2]]) | |
doubles = reduce(lambda x,y: x+y, [x*2 for x in card_numbers[::2]]) | |
total = singles + doubles | |
return 'Real' if total % 10 == 0 else 'Fake' | |
def clean_test_case(test_case): | |
return [int(x) for x in reduce(lambda x,y: x+y, test_case.strip().split(' '))] | |
def execute(): | |
test_cases = open(sys.argv[1], 'r') | |
for test_case in test_cases: | |
test = clean_test_case(test_case) | |
print(check_credict_card(test)) | |
test_cases.close() | |
if __name__ == '__main__': | |
execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment