功能以在两个数字之间获得最高的共同除数
我正在尝试实现一个函数,以在两个数字之间获得最高的公共除数,但是我会得到一个错误模棱两可的变量出现“ GCD”
。
gcd a 0 = 0
gcd 0 a = 0
gcd a b = if a > b
then (if mod a b == 0 then a else gcd a (b-1))
else (if mod b a == 0 then b else gcd (a-1) b)
如何执行它: 1-找到两个数字中最大的 2-最大的mod最小;如果它等于零,那么它将返回最小的,否则
它将再次调用方法,但使用(最小-1),最大的值相同
I am trying to implement a function to get the highest common divisor between two numbers, but I am getting an error Ambiguous variable occurrence "gcd"
.
gcd a 0 = 0
gcd 0 a = 0
gcd a b = if a > b
then (if mod a b == 0 then a else gcd a (b-1))
else (if mod b a == 0 then b else gcd (a-1) b)
How it will be executed:
1- find the greatest of two numbers
2- then the greatest mod smallest; if it equals zero then it will return the smallest, otherwise
it will call method again but with (smallest - 1) and the same value for the greatest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论