-
-
Notifications
You must be signed in to change notification settings - Fork 359
Minor changes to euclidean algorithm implementation in Common Lisp #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor changes to euclidean algorithm implementation in Common Lisp #609
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about Common Lisp, but I find 2 small mistakes in .md
file.
There is a weird thing, where the indentation in the Could someone try to build it on their own machine and check how it looks? EDIT: I think the .md problems from @dovisutu are fixed. |
Fixed it. This is PR is good to go in my eyes. A review is still needed and appreciated though. |
The rename confused Git, so here is the actual diff: diff --git a/euclidean_algorithm.lisp b/temp.lisp
index cff5ab2..3b8dcad 100644
--- a/euclidean_algorithm.lisp
+++ b/temp.lisp
@@ -1,33 +1,32 @@
-;;;; Euclid algorithm implementation
+;;;; Euclidean algorithm implementation in Common Lisp
(defun euclid-sub (a b)
+ "Finds the greatest common divsor for any two integers"
(euclid-sub* (abs a) (abs b)))
(defun euclid-sub* (a b)
+ "Finds the greatest common divisor for any two positive integers"
(if (eq a b)
- a
- (if (> a b)
- (euclid-sub* (- a b) b)
- (euclid-sub* a (- b a)))))
+ a
+ (if (> a b)
+ (euclid-sub* (- a b) b)
+ (euclid-sub* a (- b a)))))
(defun euclid-mod (a b)
+ "Finds the greatest common divisor for any two integers"
(if (zerop b)
- (abs a)
- (euclid-mod b (mod a b))))
+ (abs a)
+ (euclid-mod b (mod a b))))
-(print
- (euclid-sub (* 64 67)
- (* 64 81)))
-(print
- (euclid-mod (* 128 12)
- (* 128 77)))
+(print (euclid-sub (* 64 67) (* 64 81)))
+(print (euclid-mod (* 128 12) (* 128 77)))
-;; built-in function: (gcd 80 40)
-;; quick test
-(assert
- (= (euclid-sub (* 64 67) (* 64 81))
- (gcd (* 64 67) (* 64 81))))
+;; Quick test
+(assert
+ (eql (euclid-sub (* 64 67) (* 64 81))
+ (gcd (* 64 67) (* 64 81))))
-(assert
- (= (euclid-mod (* 64 67) (* 64 81))
+(assert
+ (eql (euclid-mod (* 64 67) (* 64 81))
(gcd (* 64 67) (* 64 81))))
+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything still functionally works, so that's good. I also approve of the change from =
to eql
according to https://stackoverflow.com/a/548774. Just a few nits left.
(I have noticed that out of the box, Emacs does not indent CL like this, so I'll provide some instructions on the wiki for those of us who use it on changing that.)
5ac602a
to
329f333
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. The breakage is due to some transitive dependencies having nothing to do with your code (see #620 (comment)). I'll wait to merge until we know more about that.
@Trashtalk217 Something I commented on indirectly: the file rename made it hard to compare changes (see #609 (comment)). If you're going to do a file rename, in order for Git to not get confused, it's best to either
This way you can force |
The euclidean algorithm was the first algorithm I ever implemented in Common Lisp and it is due for a revision. I added docstrings and did some changes to imdentation. I also did some research into turning the two functions for
euclid-sub
and turning it into one single function. I decided against it since alternative implementations were slower.That's about it, some very small changes to make the code slightly better.