Skip to content

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

Merged
merged 10 commits into from
Oct 5, 2018

Conversation

kenpower
Copy link
Contributor

@kenpower kenpower commented Oct 3, 2018

No description provided.

@Gathros Gathros added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Hacktoberfest The label for all Hacktoberfest related things! labels Oct 3, 2018
Copy link
Member

@jiegillet jiegillet left a 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))

}
Copy link
Member

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))
Copy link
Member

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{
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, forgot about that.

@jiegillet jiegillet self-assigned this Oct 3, 2018
Copy link
Member

@jiegillet jiegillet left a 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 =
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Member

@jiegillet jiegillet left a 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!

@jiegillet jiegillet merged commit 285e3db into algorithm-archivists:master Oct 5, 2018
kenpower added a commit to kenpower/algorithm-archive that referenced this pull request Oct 22, 2018
* add Scala example for Euclidean

* deal with negative args and zero

* deal with negative args and zero

* rename function

* change method name

* fix typo
@kenpower kenpower deleted the euclidean_in_scala branch March 26, 2021 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest The label for all Hacktoberfest related things! Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants