-
-
Notifications
You must be signed in to change notification settings - Fork 359
add Scala implementation for Euclidean #427
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
add Scala implementation for Euclidean #427
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.
Thank you for this nice contribution. I have a few requests for you :)
println(euclid(135749,27482)) | ||
println(euclid_mod(135749,27482)) | ||
|
||
} |
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.
End the file on a newline
} | ||
|
||
def main(args: Array[String]): Unit = | ||
println(euclid(135749,27482)) |
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.
Could you write these numbers as their prime decomposition? Just so its obvious what the answer should be.
object Euclid { | ||
|
||
def euclid(a: Int, b: Int):Int = | ||
(a,b) match{ |
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.
Most other implementations take the absolute value of the input to avoid problems with negative numbers. Maybe you could have a wrapper that takes care of that, and also the case when one number is zero while we're at it.
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.
Thanks, forgot about that.
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.
One more round :)
@@ -0,0 +1,22 @@ | |||
object Euclid { | |||
|
|||
def euclid(a: Int, b: Int): Int = |
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.
Could you rename it to euclid_sub
?
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.
OK. You're concerned about having Euclid
and euclid
in same namespace?
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.
Not really, it's just more readable when you have 2 methods based on subtraction and modulo
…rithm-archive into euclidean_in_scala
…rithm-archive into euclidean_in_scala
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.
Code is good!
One last thing, in the .md
file, when you have [import, lang="Scala"]
the name of the language should not have a capital letter. You changed Fortran as well above Scala. Fix that and it's a merge!
…rithm-archive into euclidean_in_scala
* add Scala example for Euclidean * deal with negative args and zero * deal with negative args and zero * rename function * change method name * fix typo
No description provided.