Skip to content
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

feat: Added a function for finding the least common multiple #840

Merged
merged 6 commits into from
Jun 12, 2020
Merged

feat: Added a function for finding the least common multiple #840

merged 6 commits into from
Jun 12, 2020

Conversation

tjgurwara99
Copy link
Member

Description of Change

I have added a function that outputs the least common multiple of two numbers.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • Sort by alphabetical order
  • I acknowledge that all my contributions will be made under the project's license.

Notes: Function to find the least common multiple of two numbers.

math/least_common_multiple.cpp Show resolved Hide resolved
@@ -0,0 +1,41 @@
// Copyright 2020 @author tjgurwara99
Copy link
Member

Choose a reason for hiding this comment

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

Please change this to a comment structure like:

/**
 * Copyright 2020 @author tjgurwara99
 * @file
 *
 * (basic description about the program here)

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

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

Everything seems to be good (apart from the above). 👍

Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

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

i suggest you to write some test cases to validate the algorithm properly, please add a function void tests() and write some tests in this functions using assert statements and call this function from main()

@tjgurwara99
Copy link
Member Author

I have taken onboard all the comments and tried to fix the issues, please take a look now.

@ayaankhan98
Copy link
Member

@tjgurwara99 have a look at #807 files are very well documented in this PR, please do the documentaion in similar manner.
Thanks! for your contribution

Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

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

looks good

@tjgurwara99 tjgurwara99 reopened this Jun 12, 2020
@ayaankhan98 ayaankhan98 merged commit 1b5dee7 into TheAlgorithms:master Jun 12, 2020
* @params two integers x and y whose gcd we want to find.
* @return greatest common divisor of x and y.
*/
unsigned int gcd(unsigned int x, unsigned int y) {
Copy link
Collaborator

@kvedala kvedala Jun 13, 2020

Choose a reason for hiding this comment

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

Could you make another pull request in which the functions are templated?

Eg, gcd and lcm Function inputs can be short, int, long, long long, signed or unsigned.

template<typename T>
gcd(const T &a, const T &b)
{....}

Because it is a recursive function, use of const references gives a faster memory access. If the arguments cannot be made const references, that’s ok

Copy link
Member Author

Choose a reason for hiding this comment

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

@kvedala I have opened another pull request #845. Once that is complete I'll create a new pull request for these changes.


/**
* Function for finding greatest common divisor of two numbers.
* @params two integers x and y whose gcd we want to find.
Copy link
Collaborator

@kvedala kvedala Jun 13, 2020

Choose a reason for hiding this comment

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

The syntax is incorrect please refer #807 and this link

Good documentation, but would not generate correct output.

/**
 @param <variable name> description
 @param <Second variable name> description
 */

/**
* Function for finding the least common multiple of two numbers.
* @params integer x and y whose lcm we want to find.
* @return lcm of x and y using the relation x * y = gcd(x, y) * lcm(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use LaTeX syntax for math formulae in the documentation:

\f$x \cdot y = \mathrm{gcd}(x, y) \cdot /mathrm{lcm}(x, y)\f$

Example output

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know about this feature of Doxygen, thanks for pointing it out!

@kvedala
Copy link
Collaborator

kvedala commented Jun 14, 2020

@tjgurwara99 This is the autogenerated documentation for this file -> link. Note:

  1. the correct tag is param and not params. hence, all the parameter tags got ignored
  2. no \brief tag in the beginning of the file did not create any summary in the list of files page
    Thought the points would help you going forward and this was another point I realized should keep an eye while reviewing 😄

@tjgurwara99
Copy link
Member Author

@tjgurwara99 This is the autogenerated documentation for this file -> link. Note:

  1. the correct tag is param and not params. hence, all the parameter tags got ignored
  2. no \brief tag in the beginning of the file did not create any summary in the list of files page
    Thought the points would help you going forward and this was another point I realized should keep an eye while reviewing 😄

@kvedala Could you show me the config file (cmake or Doxyfile) you use for Doxygen, I want to try and add that to other projects but don't seem to be able to do it.

@kvedala
Copy link
Collaborator

kvedala commented Jun 14, 2020

@tjgurwara99 This is the autogenerated documentation for this file -> link. Note:

  1. the correct tag is param and not params. hence, all the parameter tags got ignored
  2. no \brief tag in the beginning of the file did not create any summary in the list of files page
    Thought the points would help you going forward and this was another point I realized should keep an eye while reviewing 😄

@kvedala Could you show me the config file (cmake or Doxyfile) you use for Doxygen, I want to try and add that to other projects but don't seem to be able to do it.

In my setup, the doxygen gets configured by cmake itself. -> right here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants