问题标签 [luhn]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
luhn - 如何使用 luhn 算法计算十六进制 IMEI(数字+字符)的校验位?
我想了解逻辑,以便我可以在 java 中实现这个算法。我想计算有效的十六进制 IMEI 号码的校验位。例如 - 6C4BFFC0000004 请帮我解决算法。我试图在谷歌中找到解决方案,但我无法使用这些算法找到正确的答案。
但是上面 IMEI 的校验位是 4。我得到了 7。我不知道我哪里出错了。
database - 在访问中应用 Lunh 算法
有人知道我如何在访问中应用 Lahn 算法,用电话号码验证参考号码
c - Luhn 算法有时工作有时失败
如果它符合算法,它应该有一个输出真,如果它不,输出应该是假的。知道哪里出错了吗?
我试过了
代码
credit-card - 是否有任何有效的信用卡号是其他有效信用卡号的初始子字符串?
我正在尝试实现对有效信用卡号的识别,以便我可以过渡到下一个字段。鉴于信用卡号有各种长度,我的问题是我是否可以指望这样一个事实:如果我确认一个有效的信用卡号(通过正则表达式和 Luhn 算法使用),我不会排除其他有效的信用卡号(就正则表达式/Luhn 和发行而言)更长。
c - 用 C 语言编写程序以应用 Luhn 算法进行信用卡验证
我需要我的程序提示用户输入并在输入不遵循信用卡格式(例如:负数或字母等)的情况下重新提示,然后应用算法查看数字是否为有效的信用卡号码,如果是,是 Visa、MasterCard 还是 AmEx。
我知道这个问题已经在这个网站上用不同的代码回答了,我发誓我阅读了我可能找到的所有东西(在这个网站和网络上的其他地方),但我很难理解 C 语法,我想尝试自己想出一些东西,而不是从其他答案中复制一些我不理解的代码。如果有人可以帮助我并看看我到目前为止所做的事情并告诉我我做错了什么,我将非常感激。此外,任何可以帮助我更好地理解 C 语法逻辑的提示将不胜感激。
我的程序正在编译,但是当我运行它时,它以一种非常奇怪的方式运行:当我输入一个输入时,有时它会说它是无效的(即使它是一个有效的数字),有时它在我按下后它不会返回任何东西不管按回车键多少次都不会停止运行。
到目前为止,这是我的代码:
python - 卢恩斯算法
嘿,我正在为学校的作业做 Luhn 的算法。
一些输出以正确的方式出现;但是,有些不是。
0004222222222222
给我一共44
,
和
0378282246310005
给我一共48
,
举几个例子。
我知道我的代码不是最干净的,因为我是新手,但如果有人能确定我的错误在哪里,我将不胜感激
这是我的代码:
python - 不确定如何修复此错误 Luhn Algorithm PYTHON
好吧,所以我想我快到了,我的第一/第二部分在他们自己的情况下工作完美,但我无法将两者结合起来这是我到目前为止所拥有的,我认为错误在于最后一点,抱歉,我是 python 新手,所以我希望尽快掌握它
Edit3:我已经让它工作了(在你们的帮助下)但是现在当我输入 3782822463100050 时,它假设是无效的美国运通,但它显示为有效的美国运通......
Edit1:好的,例如,当我发布0378282246310005
(假美国运通)时,它说
0378282246310005
但是当我像它一样插入一个随机数时
请输入您的信用卡号 0378282246310005
我们不接受那种卡
Edit2:最后你应该能够输入信用卡号码,它会说“你的“信用卡类型”是有效的(或无效的)
或者说“我们不支持该卡”
algorithm - Check a valid credit card number using python
This is a homework assignment that I've been working on to compute if a credit card number is valid. It has many steps and uses 2 other helper functions.
The first helper function makes a list consisting of each digit in n:
The second helper function adds the sum of digits in a number. For example:
So the function I am working on is suppose to validate a 16 digit credit card number. It has specific orders to follow in the order given.
- Verifies that it contains only digits. #Done.
- Verifies that it is 16 digits long. #Done.
- if n is a string, it converts it to an integer.
- creates a list using the function intToList(n).
- Multiplies the odd indices of the list made by intToList(n) by 2 and any products that produce two-digit numbers are replaced by the sum of the digits using the function addDigits(n).
- Computes the sum of all the single digits in the list made my intToList(n). If the sum is equal to 0 modulo 10, the original value, n, is a valid credit card number.
As of right now I have this:
Here is my issue, I am unsure where to go from here. I am pretty sure the code above is correct so far, but I don't know how to make the products that produce two-digit numbers compute to single digit ones using my function and computes the sum of all the single digits in the list.
Any help would be greatly appreciated. Let me know if I can clear anything up.
added what I've worked on.
python - Python信用卡验证
我是 Python 初学者,目前正在研究 Luhn 算法来检查信用卡验证。我编写了大部分代码,但我遇到了 2 个错误,我得到的第一个错误是在分配之前引用了 num。我得到的第二个是'_io.TextIOWrapper'类型的对象没有len()。进一步的帮助/指导将不胜感激。
这些是 Luhn 算法(Mod10 检查)的步骤
- 从右到左每隔一个数字加倍。如果这种“加倍”产生两位数,则将两位数相加得到一位数。
- 现在添加步骤 1 中的所有个位数。
- 将信用卡号中奇数位的所有数字从右到左相加。
- 将步骤 2 和 3 的结果相加。
- 如果第 4 步的结果能被 10 整除,则卡号有效;否则无效。
这是我的输出应该是什么
这是代码。
haskell - Haskell 中的 Luhn 函数
我目前正在阅读《Haskell 编程》一书(到目前为止这本书绝对令人惊叹),但在练习 4.8.8 中遇到了问题。
任务是在 Haskell 中实现Luhn 算法,使用帮助函数luhnDouble :: Int -> Int
(如果结果大于 9,则将数字加倍并减去 9)和函数mod
。
实现该luhnDouble
功能没有问题,但我正在努力将它们都带入 type 的功能Int -> Int -> Int -> Int -> Bool
。
我尝试过两种方式:
我收到类型错误。
但是我不是将函数 4Int
作为参数并Bool
因此得到 a 吗?
然后我尝试对函数进行柯里化并使用lambda 表达式:
但是我不确定如何if
在这里引入表达式来获得一个Bool
值。
任何人都可以帮助我,并给我一个提示,我该如何解决这个问题?