Problem 4: GCD (100 pts)
let's implement the gcd
function that finds the greatest common divisor of two positive integers. The remainder
function that computes the remainder of two positive integers is given. It takes two integers as inputs and returns an integer of solution. A Python version is provided in case you forget about how to compute gcd
using Euclidean algorithm.
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
(define (remainder a b)
(- a (* b (quotient a b))))
(define (gcd a b)
'YOUR-CODE-HERE
)
;;; Tests
; (gcd 2 3)
; 1
; (gcd 16 12)
; 4