Greatest common divisor: Difference between revisions

Content added Content deleted
Line 1,898: Line 1,898:
Racket provides a built-in gcd function. Here's a program that computes the gcd of 14 and 63:
Racket provides a built-in gcd function. Here's a program that computes the gcd of 14 and 63:


<lang Racket>#lang racket
<lang racket>#lang racket


(gcd 14 63)</lang>
(gcd 14 63)</lang>
Line 1,904: Line 1,904:
Here's an explicit implementation. Note that since Racket is tail-calling, the memory behavior of this program is "loop-like", in the sense that this program will consume no more memory than a loop-based implementation.
Here's an explicit implementation. Note that since Racket is tail-calling, the memory behavior of this program is "loop-like", in the sense that this program will consume no more memory than a loop-based implementation.


<lang Racket>#lang racket
<lang racket>#lang racket


;; given two nonnegative integers, produces their greatest
;; given two nonnegative integers, produces their greatest