Skip to content

Commit e1953bb

Browse files
committed
changed the euclid-sub function and fixed issues
1 parent db00304 commit e1953bb

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

contents/euclidean_algorithm/code/clisp/euclidean.lisp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
(defun euclid-sub (a b)
44
"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)))))
512
(euclid-sub* (abs a) (abs b)))
613

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-
1514
(defun euclid-mod (a b)
1615
"Finds the greatest common divisor for any two integers"
1716
(if (zerop b)
@@ -23,10 +22,9 @@
2322

2423
;; Quick test
2524
(assert
26-
(eql (euclid-sub (* 64 67) (* 64 81))
25+
(eql (euclid-sub (* 64 67) (* 64 81))
2726
(gcd (* 64 67) (* 64 81))))
2827

2928
(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))))

0 commit comments

Comments
 (0)