Skip to content

Commit

Permalink
Revert "Merge branch 'master' into cstdint"
Browse files Browse the repository at this point in the history
This reverts commit aba74d8, reversing
changes made to d40099a.
  • Loading branch information
realstealthninja committed Oct 10, 2024
1 parent aba74d8 commit a670025
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 879 deletions.
3 changes: 0 additions & 3 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@

## Greedy Algorithms
* [Boruvkas Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/boruvkas_minimum_spanning_tree.cpp)
* [Digit Separation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/digit_separation.cpp)
* [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/dijkstra.cpp)
* [Gale Shapley](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/gale_shapley.cpp)
* [Huffman](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/huffman.cpp)
Expand Down Expand Up @@ -301,7 +300,6 @@
* [Iterative Tree Traversals](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/iterative_tree_traversals.cpp)
* [Kadanes3](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/kadanes3.cpp)
* [Kelvin To Celsius](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/kelvin_to_celsius.cpp)
* [Lfu Cache](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/lfu_cache.cpp)
* [Lru Cache](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/lru_cache.cpp)
* [Matrix Exponentiation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/matrix_exponentiation.cpp)
* [Palindrome Of Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/palindrome_of_number.cpp)
Expand Down Expand Up @@ -371,7 +369,6 @@
* [Gnome Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/gnome_sort.cpp)
* [Heap Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/heap_sort.cpp)
* [Insertion Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/insertion_sort.cpp)
* [Insertion Sort Recursive](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/insertion_sort_recursive.cpp)
* [Library Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/library_sort.cpp)
* [Merge Insertion Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/merge_insertion_sort.cpp)
* [Merge Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/sorting/merge_sort.cpp)
Expand Down
142 changes: 0 additions & 142 deletions greedy_algorithms/digit_separation.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions math/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ template <typename T>
T cylinder_surface_area(T radius, T height) {
return 2 * M_PI * radius * height + 2 * M_PI * pow(radius, 2);
}

/**
* @brief surface area of a [hemi-sphere](https://en.wikipedia.org/wiki/Surface_area) ( 3 *
* pi * r^2)
* @param radius is the radius of the hemi-sphere
* @tparam T datatype of radius
* @returns surface area of the hemi-sphere
*/
template <typename T>
T hemi_sphere_surface_area(T radius) {
return 3 * M_PI * pow(radius, 2);
}
} // namespace math

/**
Expand Down Expand Up @@ -279,18 +267,6 @@ static void test() {
std::cout << "Output: " << double_area << std::endl;
assert(double_area == double_expected);
std::cout << "TEST PASSED" << std::endl << std::endl;

// 11th test
double_radius = 10.0;
double_expected = 942.4777960769379;
double_area = math::hemi_sphere_surface_area(double_radius);

std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl;
std::cout << "Input Radius: " << double_radius << std::endl;
std::cout << "Expected Output: " << double_expected << std::endl;
std::cout << "Output: " << double_area << std::endl;
assert(double_area == double_expected);
std::cout << "TEST PASSED" << std::endl << std::endl;
}

/**
Expand Down
85 changes: 43 additions & 42 deletions math/fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
/**
* @file
* @brief n-th [Fibonacci
* number](https://en.wikipedia.org/wiki/Fibonacci_sequence).
* @brief Generate fibonacci sequence
*
* @details
* Naive recursive implementation to calculate the n-th Fibonacci number.
* Calculate the the value on Fibonacci's sequence given an
* integer as input.
* \f[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\f]
*
* @see fibonacci_large.cpp, fibonacci_fast.cpp, string_fibonacci.cpp
*/

#include <cstdint> /// for std::uint64_t
#include <cassert> /// for assert
#include <iostream> /// for IO operations

/**
* @namespace math
* @brief Math algorithms
*/
namespace math {
#include <cassert>
#include <cstdint>
#include <iostream>
/**
* @namespace fibonacci
* @brief Functions for Fibonacci sequence
*/
namespace fibonacci {
/**
* @brief Function to compute the n-th Fibonacci number
* @param n the index of the Fibonacci number
* @returns n-th element of the Fibonacci's sequence
* Recursively compute sequences
* @param n input
* @returns n-th element of the Fbinacci's sequence
*/
uint64_t fibonacci(uint64_t n) {
// If the input is 0 or 1 just return the same (Base Case)
// This will set the first 2 values of the sequence
/* If the input is 0 or 1 just return the same
This will set the first 2 values of the sequence */
if (n <= 1) {
return n;
}

// Add the preceding 2 values of the sequence to get next
/* Add the last 2 values of the sequence to get next */
return fibonacci(n - 1) + fibonacci(n - 2);
}
} // namespace fibonacci
} // namespace math

/**
* @brief Self-test implementation
* Function for testing the fibonacci() function with a few
* test cases and assert statement.
* @returns `void`
*/
static void test() {
assert(math::fibonacci::fibonacci(0) == 0);
assert(math::fibonacci::fibonacci(1) == 1);
assert(math::fibonacci::fibonacci(2) == 1);
assert(math::fibonacci::fibonacci(3) == 2);
assert(math::fibonacci::fibonacci(4) == 3);
assert(math::fibonacci::fibonacci(15) == 610);
assert(math::fibonacci::fibonacci(20) == 6765);
std::cout << "All tests have passed successfully!\n";
uint64_t test_case_1 = fibonacci(0);
assert(test_case_1 == 0);
std::cout << "Passed Test 1!" << std::endl;

uint64_t test_case_2 = fibonacci(1);
assert(test_case_2 == 1);
std::cout << "Passed Test 2!" << std::endl;

uint64_t test_case_3 = fibonacci(2);
assert(test_case_3 == 1);
std::cout << "Passed Test 3!" << std::endl;

uint64_t test_case_4 = fibonacci(3);
assert(test_case_4 == 2);
std::cout << "Passed Test 4!" << std::endl;

uint64_t test_case_5 = fibonacci(4);
assert(test_case_5 == 3);
std::cout << "Passed Test 5!" << std::endl;

uint64_t test_case_6 = fibonacci(15);
assert(test_case_6 == 610);
std::cout << "Passed Test 6!" << std::endl << std::endl;
}

/**
* @brief Main function
* @returns 0 on exit
*/
/// Main function
int main() {
test(); // run self-test implementations
return 0;
test();
int n = 0;
std::cin >> n;
assert(n >= 0);
std::cout << "F(" << n << ")= " << fibonacci(n) << std::endl;
}
Loading

0 comments on commit a670025

Please sign in to comment.