Greatest common divisor: Difference between revisions

→‎{{header|Common Lisp}}: Fix gcd2; it was returning wrong result. Want (mod a b), not (mod n b).
m (Sort C# < Clojure.)
(→‎{{header|Common Lisp}}: Fix gcd2; it was returning wrong result. Want (mod a b), not (mod n b).)
Line 411:
 
=={{header|Common Lisp}}==
Common Lisp provides a ''gcd'' function.
We call the function <code>gcd2</code> so as not to conflict with <code>common-lisp:gcd</code>.
 
<lang lisp>(defun gcd2 (a b)
<lang lisp>CL-USER> (gcd 2345 5432)
(do ((n a)) ((zerop b) (abs a))
7</lang>
(shiftf n a b (mod n b)))) ; Tried it, doesn't work</lang>
 
Here is an implementation. We call the function <code>gcd2</code> so as not to conflict with <code>common-lisp:gcd</code>.
 
<lang lisp>(defun gcd2 (a b)
(do ((n a)) ((zerop b) (abs a))
(shiftf n a b (mod na b)))) ; Tried it, doesn't work</lang>
 
=={{header|CoffeeScript}}==
Anonymous user