递归和信用卡的Luhn算法

BabbleDay posted @ 2015年6月30日 22:15 in 见过的PL们 with tags Python Recursion Luhn Algorithm , 692 阅读

这里用python做一个mutual recursion

 

def split(n):
    return n//10, n%10

def luhn_sum(n):
    if n<10:
        return n
    else:
        rest, last = split(n)
        return luhn_double_sum(rest) + last

def luhn_double_sum(n):
    rest, last = split(n)
    luhn_digit = split(2*last)[0] + split(2*last)[1]
    if n<10:
        return luhn_digit
    else:
        rest, last = split(n)
        return luhn_sum(rest) + luhn_digit

 

Avatar_small
LIC Online Payment L 说:
2023年1月23日 23:35

Life Insurance Corporation was established in 1956 and Is the oldest insurance company in India, and it has been providing millions of individuals with a variety of insurance schemes along with giving a good service to business groups. LIC Online Payment Login To have a successful policy on your name, it is mandatory to make the LIC online premium payment or offline in time, and timely paying the installments of LIC will keep your policy active and that will be helpful in your emergency.

Avatar_small
PNB Net Banking 说:
2023年1月28日 04:44

Punjab National Bank is a popular yet most preferred National Bank in India, and the Net Banking service for the bank allows its customers to utilize different services online without investing in the branch. PNB Net Banking As the modern days are invoking with the technology, the services from Banks through their Net Banking feature are in good spike, and there are multiple benefits for the customer who does get the access to the PNB Net Banking service.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter