forked from algorithm-archivists/algorithm-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuclidalg.ss
18 lines (15 loc) · 1.01 KB
/
euclidalg.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(define (euclid-sub a b)
(cond
[(or (negative? a)(negative? b))(euclid-sub (abs a)(abs b))]
[(eq? a b) a]
[(> a b)(euclid-sub(- a b) b)]
[else
(euclid-sub a (- b a))]))
(define (euclid-mod a b)
(if (zero? b)
a
(euclid-mod b (modulo a b))))
(display "[#]\nModulus-based euclidean algorithm result:") (newline)
(display (euclid-mod (* 64 67) (* 64 81))) (newline)
(display "[#]\nSubtraction-based euclidean algorithm result:") (newline)
(display (euclid-sub (* 128 12) (* 128 77))) (newline)