From e3f63822192c96322331eb2dd887c583ec292c40 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Sat, 17 Oct 2020 19:31:30 +0530 Subject: [PATCH 01/21] Create magic_number.cpp This Pull Request is for HacktoberFest 2020 --- math/magic_number.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 math/magic_number.cpp diff --git a/math/magic_number.cpp b/math/magic_number.cpp new file mode 100644 index 000000000..4a6edac4f --- /dev/null +++ b/math/magic_number.cpp @@ -0,0 +1,67 @@ +/** + * @file magic_number.cpp + * @brief A simple program to check if the given number is a magic number or not. + * A number is said to be a magic number, if the sum of its digits are calculated + * till a single digit recursively by adding the sum of the digits after every addition. + * If the single digit comes out to be 1,then the number is a magic number. + * @detail This is a shortcut method to verify Magic Number. + * On dividing the input by 9, if the remainder is 1 then the number is a magic number else not. + * The divisibility rule of 9 says that a number is divisible by 9 if the sum of its digits + * are also divisible by 9. Therefore, if a number is divisible by 9, then, recursively, + * all the digit sums are also divisible by 9. The final digit sum is always 9. + * An increase of 1 in the original number will increase the ultimate value by 1, + * making it 10 and the ultimate sum will be 1, thus verifying that it is a magic number. + * @author [Neha Hasija](https://github.com/neha-hasija17) + */ +#include +#include + +/** + * Function to check if the given number is magic number or not. + * @param n number to be checked. + * @return if number is a magic number, returns true, else false. + */ + +bool magic_number(int n) { + if (n <= 0) { + return false; + } + // result stores the modulus of @param n with 9 + int result=n%9; + //if result is 1 then the number is a magic number else not + if(result==1) return true; + else return false; +} + +/** Test function + * @returns void + */ +void tests() { + std::cout << "Test 1:\t n=60\n"; + assert(magic_number(60) == false); + std::cout << "passed\n"; + + std::cout << "Test 2:\t n=730\n"; + assert(magic_number(730) == true); + std::cout << "passed\n"; + + std::cout << "Test 3:\t n=0\n"; + assert(magic_number(0) == false); + std::cout << "passed\n"; + + std::cout << "Test 4:\t n=479001600\n"; + assert(magic_number(479001600) == false); + std::cout << "passed\n"; + + std::cout << "Test 5:\t n=-35\n"; + assert(magic_number(-35) == false); + std::cout << "passed\n"; +} + +/** Main function + * @returns 0 on exit + */ +int main() { + tests(); + return 0; +} From 579a290acb5cf0d0f346e5613d7ff296cbf068d0 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Mon, 19 Oct 2020 01:42:31 +0530 Subject: [PATCH 02/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 4a6edac4f..dd5cdc28f 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -36,7 +36,7 @@ bool magic_number(int n) { /** Test function * @returns void */ -void tests() { +static void tests() { std::cout << "Test 1:\t n=60\n"; assert(magic_number(60) == false); std::cout << "passed\n"; From f03910abdcc11826a3912bddf6bd2f96aeefd145 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Mon, 19 Oct 2020 01:42:38 +0530 Subject: [PATCH 03/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index dd5cdc28f..c6be43a9f 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -1,5 +1,5 @@ /** - * @file magic_number.cpp + * @file * @brief A simple program to check if the given number is a magic number or not. * A number is said to be a magic number, if the sum of its digits are calculated * till a single digit recursively by adding the sum of the digits after every addition. From db3f694490ca8db5e2ef71484dc06992ee3d4cf1 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Mon, 19 Oct 2020 01:42:47 +0530 Subject: [PATCH 04/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index c6be43a9f..de0a8fde3 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -4,7 +4,8 @@ * A number is said to be a magic number, if the sum of its digits are calculated * till a single digit recursively by adding the sum of the digits after every addition. * If the single digit comes out to be 1,then the number is a magic number. - * @detail This is a shortcut method to verify Magic Number. + * + * This is a shortcut method to verify Magic Number. * On dividing the input by 9, if the remainder is 1 then the number is a magic number else not. * The divisibility rule of 9 says that a number is divisible by 9 if the sum of its digits * are also divisible by 9. Therefore, if a number is divisible by 9, then, recursively, From 581715db048ae272ee048708dc018444dfaba7dc Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:13:56 +0000 Subject: [PATCH 05/21] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 1aaf9dade..fa314c02e 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -141,6 +141,7 @@ * [Large Factorial](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/large_factorial.cpp) * [Large Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/large_number.h) * [Least Common Multiple](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/least_common_multiple.cpp) + * [Magic Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/magic_number.cpp) * [Miller Rabin](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/miller_rabin.cpp) * [Modular Inverse Fermat Little Theorem](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/modular_inverse_fermat_little_theorem.cpp) * [Number Of Positive Divisors](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/number_of_positive_divisors.cpp) From a6b57f8896343da39fd312115b819c1c111076b6 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:14:12 +0000 Subject: [PATCH 06/21] clang-format and clang-tidy fixes for db3f6944 --- math/magic_number.cpp | 35 ++++++------ sorting/pancake_sort.cpp | 112 ++++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 70 deletions(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index de0a8fde3..c55225754 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -1,17 +1,19 @@ /** * @file - * @brief A simple program to check if the given number is a magic number or not. - * A number is said to be a magic number, if the sum of its digits are calculated - * till a single digit recursively by adding the sum of the digits after every addition. - * If the single digit comes out to be 1,then the number is a magic number. + * @brief A simple program to check if the given number is a magic number or + * not. A number is said to be a magic number, if the sum of its digits are + * calculated till a single digit recursively by adding the sum of the digits + * after every addition. If the single digit comes out to be 1,then the number + * is a magic number. * - * This is a shortcut method to verify Magic Number. - * On dividing the input by 9, if the remainder is 1 then the number is a magic number else not. - * The divisibility rule of 9 says that a number is divisible by 9 if the sum of its digits - * are also divisible by 9. Therefore, if a number is divisible by 9, then, recursively, - * all the digit sums are also divisible by 9. The final digit sum is always 9. - * An increase of 1 in the original number will increase the ultimate value by 1, - * making it 10 and the ultimate sum will be 1, thus verifying that it is a magic number. + * This is a shortcut method to verify Magic Number. + * On dividing the input by 9, if the remainder is 1 then the number is a magic + * number else not. The divisibility rule of 9 says that a number is divisible + * by 9 if the sum of its digits are also divisible by 9. Therefore, if a number + * is divisible by 9, then, recursively, all the digit sums are also divisible + * by 9. The final digit sum is always 9. An increase of 1 in the original + * number will increase the ultimate value by 1, making it 10 and the ultimate + * sum will be 1, thus verifying that it is a magic number. * @author [Neha Hasija](https://github.com/neha-hasija17) */ #include @@ -28,10 +30,13 @@ bool magic_number(int n) { return false; } // result stores the modulus of @param n with 9 - int result=n%9; - //if result is 1 then the number is a magic number else not - if(result==1) return true; - else return false; + int result = n % 9; + // if result is 1 then the number is a magic number else not + if (result == 1) { + return true; + } else { + return false; + } } /** Test function diff --git a/sorting/pancake_sort.cpp b/sorting/pancake_sort.cpp index accc5dbdb..e372e6097 100644 --- a/sorting/pancake_sort.cpp +++ b/sorting/pancake_sort.cpp @@ -1,26 +1,25 @@ /** * @file - * @brief pancake sort sorts a disordered stack of pancakes by flipping any number of pancakes using a spatula using minimum number of flips. + * @brief pancake sort sorts a disordered stack of pancakes by flipping any + * number of pancakes using a spatula using minimum number of flips. * * @details - * Unlike a traditional sorting algorithm, which attempts to sort with the fewest comparisons possible, - * the goal is to sort the sequence in as few reversals as possible. - * Overall time complexity of pancake sort is O(n^2) - * For example: example 1:- - * Disordered pancake sizes: {2,5,3,7,8} - * Sorted: {2,3,5,7,8} - * For example: example 2:- - * Disordered pancake sizes: {22,51,37,73,81} - * Sorted: {22,37,51,73,81} + * Unlike a traditional sorting algorithm, which attempts to sort with the + * fewest comparisons possible, the goal is to sort the sequence in as few + * reversals as possible. Overall time complexity of pancake sort is O(n^2) For + * example: example 1:- Disordered pancake sizes: {2,5,3,7,8} Sorted: + * {2,3,5,7,8} For example: example 2:- Disordered pancake sizes: + * {22,51,37,73,81} Sorted: {22,37,51,73,81} * @author [Divyansh Gupta](https://github.com/divyansh12323) * @see more on [Pancake sort](https://en.wikipedia.org/wiki/Pancake_sorting) - * @see related problem at [Leetcode](https://leetcode.com/problems/pancake-sorting/) -*/ + * @see related problem at + * [Leetcode](https://leetcode.com/problems/pancake-sorting/) + */ -#include // for io operations -#include // for std::vector #include // for std::is_sorted #include // for std::assert +#include // for io operations +#include // for std::vector /** * @namespace sorting @@ -29,52 +28,54 @@ namespace sorting { /** * @namespace pancake_sort - * @brief Functions for [Pancake sort](https://en.wikipedia.org/wiki/Pancake_sorting) algorithm + * @brief Functions for [Pancake + * sort](https://en.wikipedia.org/wiki/Pancake_sorting) algorithm */ namespace pancake_sort { - /** - * @brief This implementation is for reversing elements in a a C-style array . - * @param [start,end] arr our vector of elements. - * @param start starting index of array - * @param end ending index of array - * @returns void - */ - template - void reverse(std::vector &arr, int start, int end) { - T temp; //Temporary variable - while (start <= end) { - temp = arr[start]; - arr[start] = arr[end]; - arr[end] = temp; - start++; - end--; - } +/** + * @brief This implementation is for reversing elements in a a C-style array . + * @param [start,end] arr our vector of elements. + * @param start starting index of array + * @param end ending index of array + * @returns void + */ +template +void reverse(std::vector &arr, int start, int end) { + T temp; // Temporary variable + while (start <= end) { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; } - /** - * @brief This implementation is for a C-style array input that gets modified in place. - * @param [start,end] arr our vector of elements. - * @param size size of given array - * @returns 0 on exit - */ - template - int pancakeSort(std::vector &arr, int size) { - for (int i = size; i > 1; --i) { - int max_index = 0, j; //intialize some variables. - T max_value = 0; - for (j = 0; j < i; j++) { - if (arr[j] >= max_value) { - max_value = arr[j]; - max_index = j; - } - } - if (max_index != i - 1) //check for reversing - { - reverse(arr, 0, max_index); - reverse(arr, 0, i - 1); +} +/** + * @brief This implementation is for a C-style array input that gets modified in + * place. + * @param [start,end] arr our vector of elements. + * @param size size of given array + * @returns 0 on exit + */ +template +int pancakeSort(std::vector &arr, int size) { + for (int i = size; i > 1; --i) { + int max_index = 0, j = 0; // intialize some variables. + T max_value = 0; + for (j = 0; j < i; j++) { + if (arr[j] >= max_value) { + max_value = arr[j]; + max_index = j; } } - return 0; + if (max_index != i - 1) // check for reversing + { + reverse(arr, 0, max_index); + reverse(arr, 0, i - 1); + } } + return 0; +} } // namespace pancake_sort } // namespace sorting @@ -98,7 +99,8 @@ static void test() { // example 2: vector of double const int size2 = 8; std::cout << "\nTest 2- as std::vector..."; - std::vector arr2 = {23.56, 10.62, 200.78, 111.484, 3.9, 1.2, 61.77, 79.6}; + std::vector arr2 = {23.56, 10.62, 200.78, 111.484, + 3.9, 1.2, 61.77, 79.6}; sorting::pancake_sort::pancakeSort(arr2, size2); assert(std::is_sorted(arr2.begin(), arr2.end())); std::cout << "Passed\n"; From fe538baac45fb1a9268c0fc71fa88472329dc783 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Mon, 19 Oct 2020 01:52:20 +0530 Subject: [PATCH 07/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index c55225754..1465aa11a 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -24,7 +24,6 @@ * @param n number to be checked. * @return if number is a magic number, returns true, else false. */ - bool magic_number(int n) { if (n <= 0) { return false; From 676db2e57b9d56b3f3875c487cf0f61b4942f418 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 10:37:32 +0530 Subject: [PATCH 08/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 1465aa11a..0ee714671 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -16,8 +16,8 @@ * sum will be 1, thus verifying that it is a magic number. * @author [Neha Hasija](https://github.com/neha-hasija17) */ -#include -#include +#include /// for assert +#include /// for io operations /** * Function to check if the given number is magic number or not. From 7672e3998c84398b270bd50539e404a5a2603705 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 10:37:51 +0530 Subject: [PATCH 09/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 0ee714671..fb0b30468 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -38,7 +38,8 @@ bool magic_number(int n) { } } -/** Test function +/** + * @brief Test function * @returns void */ static void tests() { From 45dc717621b9fa789b1b71f3bef6c65362df3a0e Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 10:38:02 +0530 Subject: [PATCH 10/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index fb0b30468..bec86b888 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -68,6 +68,6 @@ static void tests() { * @returns 0 on exit */ int main() { - tests(); + tests(); // execute the tests return 0; } From 1e6c2d5aa049ed4e921b2fd577a06b4bc538ea49 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 21 Oct 2020 05:10:05 +0000 Subject: [PATCH 11/21] clang-format and clang-tidy fixes for 45dc7176 --- math/magic_number.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index bec86b888..3720dff65 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -16,8 +16,8 @@ * sum will be 1, thus verifying that it is a magic number. * @author [Neha Hasija](https://github.com/neha-hasija17) */ -#include /// for assert -#include /// for io operations +#include /// for assert +#include /// for io operations /** * Function to check if the given number is magic number or not. @@ -68,6 +68,6 @@ static void tests() { * @returns 0 on exit */ int main() { - tests(); // execute the tests + tests(); // execute the tests return 0; } From a19da7954517da446f1253d4001c603bf83a622e Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 10:41:16 +0530 Subject: [PATCH 12/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 3720dff65..c913c5dbd 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -37,6 +37,7 @@ bool magic_number(int n) { return false; } } +} // namespace math /** * @brief Test function From 388ee0098571230cca261db9081baa3044c45878 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 23:06:37 +0530 Subject: [PATCH 13/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index c913c5dbd..0d1fc3711 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -19,6 +19,11 @@ #include /// for assert #include /// for io operations +/** + * @namespace math + * @brief Mathematical algorithms + */ +namespace math { /** * Function to check if the given number is magic number or not. * @param n number to be checked. From 7643a23359641c9aeb19ae7f0e2add2fbf0e9a8b Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 23:36:54 +0530 Subject: [PATCH 14/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 0d1fc3711..3765b69e3 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -50,7 +50,7 @@ bool magic_number(int n) { */ static void tests() { std::cout << "Test 1:\t n=60\n"; - assert(magic_number(60) == false); + assert(math::magic_number(60) == false); std::cout << "passed\n"; std::cout << "Test 2:\t n=730\n"; From bbb182c42bd1ed9b92c91be3eef2f53b89856d7a Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 23:37:05 +0530 Subject: [PATCH 15/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 3765b69e3..6f5de1698 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -54,7 +54,7 @@ static void tests() { std::cout << "passed\n"; std::cout << "Test 2:\t n=730\n"; - assert(magic_number(730) == true); + assert(math::magic_number(730) == true); std::cout << "passed\n"; std::cout << "Test 3:\t n=0\n"; From 6359899caa483f2dcfba68cfa9f68154a3a84986 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 23:37:16 +0530 Subject: [PATCH 16/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 6f5de1698..42f02c691 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -58,7 +58,7 @@ static void tests() { std::cout << "passed\n"; std::cout << "Test 3:\t n=0\n"; - assert(magic_number(0) == false); + assert(math::magic_number(0) == false); std::cout << "passed\n"; std::cout << "Test 4:\t n=479001600\n"; From 534dacae359699324ca2bc8b2d441e3bf648b418 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 23:37:27 +0530 Subject: [PATCH 17/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 42f02c691..b00a3b858 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -62,7 +62,7 @@ static void tests() { std::cout << "passed\n"; std::cout << "Test 4:\t n=479001600\n"; - assert(magic_number(479001600) == false); + assert(math::magic_number(479001600) == false); std::cout << "passed\n"; std::cout << "Test 5:\t n=-35\n"; From 137c444398f13b8b4c5ca9270c863f0e2d4d08d3 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Wed, 21 Oct 2020 23:37:39 +0530 Subject: [PATCH 18/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index b00a3b858..389ff26d2 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -66,7 +66,7 @@ static void tests() { std::cout << "passed\n"; std::cout << "Test 5:\t n=-35\n"; - assert(magic_number(-35) == false); + assert(math::magic_number(-35) == false); std::cout << "passed\n"; } From a6526c8108c60e51c5d0471211f23f2fbbdda8a9 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Sat, 24 Oct 2020 10:36:20 +0530 Subject: [PATCH 19/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 389ff26d2..35da3b00e 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -70,7 +70,8 @@ static void tests() { std::cout << "passed\n"; } -/** Main function +/** + * @brief Main function * @returns 0 on exit */ int main() { From 69cacbc88b43b44f3c7a91c74a8471d264fcfde9 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Tue, 27 Oct 2020 06:33:14 +0530 Subject: [PATCH 20/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 35da3b00e..047278500 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -29,7 +29,7 @@ namespace math { * @param n number to be checked. * @return if number is a magic number, returns true, else false. */ -bool magic_number(int n) { +bool magic_number(const uint64_t &n) { if (n <= 0) { return false; } From 806f3251ee483a4f31b4ec4dd7e1f645a79630e9 Mon Sep 17 00:00:00 2001 From: Neha Hasija Date: Tue, 27 Oct 2020 06:33:29 +0530 Subject: [PATCH 21/21] Update math/magic_number.cpp Co-authored-by: David Leal --- math/magic_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 047278500..51232601b 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -34,7 +34,7 @@ bool magic_number(const uint64_t &n) { return false; } // result stores the modulus of @param n with 9 - int result = n % 9; + uint64_t result = n % 9; // if result is 1 then the number is a magic number else not if (result == 1) { return true;