递归和信用卡的Luhn算法

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

这里用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.

Avatar_small
Tripura 8th Class S 说:
2023年9月18日 18:00

Students can go Through the Tripura Board 8th Class Syllabus 2024 Pdf to know the Complete Details about the Examination, which is the Blueprint and the Question Pattern, Down here, we had Provided All the Tripura 8th Class Syllabus 2024 Details about the Tripura Board Class Syllabus 2024 and their PDF Download Links for All the Subjects Bengali, English, Kokborok, Hindi, Mizo , Mathematics, Science, Social Science,TBSE Class new Syllabus 2024 Pdf File Format helps to get an idea About the Concepts and Topics Taught in class for a Subject During this Academic year 2024.


登录 *


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