Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试实现验证信用卡的 Luhn 算法,有一个步骤是我们反转卡号,为什么需要反转卡号?
Luhn 算法涉及将数字中的每隔一个数字加倍,这样最右边的数字(校验位)就不会加倍。这意味着最左边的数字可能会翻倍,也可能不会翻倍,具体取决于该数字是奇数位还是偶数位。处理这种变化的一种方法是颠倒数字,并且总是以非双倍数字开头——但这对我来说似乎有点过头了;有多种解决方案(例如以相反的顺序索引数字)比反转数字的工作量少。