擅长:python、mysql、java
<p>@alko的解决方案并不适用于所有的IMEI号码:请参见有效IMEI号码的<a href="http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm" rel="nofollow">this list</a>(或实际上相同的cc号码)。在</p>
<p>以下是有效的解决方案:</p>
<pre><code>def luhn_residue(digits):
""" Lunh10 residue value """
s = sum(d if (n % 2 == 1) else (0, 2, 4, 6, 8, 1, 3, 5, 7, 9)[d]
for n, d in enumerate(map(int, reversed(digits))))
return (10 - s % 10) % 10
</code></pre>