Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def numberOfDigits(n):
- tot = 0
- while n:
- n/=10
- tot+=1
- return tot
- def isValid(n):
- n_digits = numberOfDigits(n)
- if(n_digits < 13):
- return False
- if(n_digits > 16):
- return False
- # It is not one of the 4 credit card brands
- div = 10 ** (n_digits-1)
- div2 = 10 ** (n_digits-2)
- if (n / div != 4) and (n / div != 5) and (n / div != 6) and (n / div2 != 37):
- return False
- aux = n / 10
- tot = 0
- # steps 1 and 2
- while(aux):
- digit = aux % 10
- digit = digit * 2
- digit = digit/10 + digit % 10
- tot += digit
- aux /= 100
- # step 3 nad 4
- aux = n
- while(aux):
- tot += aux % 10
- aux /= 100
- if(tot % 10 == 0):
- return True
- return False
- print isValid(100)
- print isValid(4388576018410707)
- print isValid(4388576018402626)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement