File tree 1 file changed +10
-12
lines changed
contents/euclidean_algorithm/code/clisp
1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change 2
2
3
3
(defun euclid-sub (a b)
4
4
" Finds the greatest common divsor for any two integers"
5
+ (defun euclid-sub* (a b)
6
+ " Finds the greatest common divisor for any two positive integers"
7
+ (if (eql a b)
8
+ a
9
+ (if (> a b)
10
+ (euclid-sub* (- a b) b)
11
+ (euclid-sub* a (- b a)))))
5
12
(euclid-sub* (abs a) (abs b)))
6
13
7
- (defun euclid-sub* (a b)
8
- " Finds the greatest common divisor for any two positive integers"
9
- (if (eq a b)
10
- a
11
- (if (> a b)
12
- (euclid-sub* (- a b) b)
13
- (euclid-sub* a (- b a)))))
14
-
15
14
(defun euclid-mod (a b)
16
15
" Finds the greatest common divisor for any two integers"
17
16
(if (zerop b)
23
22
24
23
; ; Quick test
25
24
(assert
26
- (eql (euclid-sub (* 64 67 ) (* 64 81 ))
25
+ (eql (euclid-sub (* 64 67 ) (* 64 81 ))
27
26
(gcd (* 64 67 ) (* 64 81 ))))
28
27
29
28
(assert
30
- (eql (euclid-mod (* 64 67 ) (* 64 81 ))
31
- (gcd (* 64 67 ) (* 64 81 ))))
32
-
29
+ (eql (euclid-mod (* 64 67 ) (* 64 81 ))
30
+ (gcd (* 64 67 ) (* 64 81 ))))
You can’t perform that action at this time.
0 commit comments