From 5ae4f90029de175de1eb5b96962b23ad9166ac38 Mon Sep 17 00:00:00 2001 From: utkarshbhola <63907963+utkarshbhola@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:27:55 +0530 Subject: [PATCH] Update fibonacci_sum.cpp changed the matrix addition function for easier readability and added a new test case where n =20 and m =30 to calculate the Fibonacci numbers from the 20th Fibonacci number (F(20)) to the 30th Fibonacci number (F(30)).This test case illustrates the capability of your fiboSum function to handle a more significant range of Fibonacci numbers and provides a meaningful result. --- math/fibonacci_sum.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/math/fibonacci_sum.cpp b/math/fibonacci_sum.cpp index 510757888..a1bb1bed1 100644 --- a/math/fibonacci_sum.cpp +++ b/math/fibonacci_sum.cpp @@ -35,16 +35,12 @@ using matrix = std::vector >; * @param A martix 2 * @returns resultant matrix */ -math::fibonacci_sum::matrix multiply(const math::fibonacci_sum::matrix &T, - const math::fibonacci_sum::matrix &A) { - math::fibonacci_sum::matrix result(2, std::vector(2, 0)); - - // multiplying matrices +math::fibonacci_sum::matrix multiply(const matrix &T, const matrix &A) { + matrix result(2, std::vector(2, 0)); result[0][0] = T[0][0] * A[0][0] + T[0][1] * A[1][0]; result[0][1] = T[0][0] * A[0][1] + T[0][1] * A[1][1]; result[1][0] = T[1][0] * A[0][0] + T[1][1] * A[1][0]; result[1][1] = T[1][0] * A[0][1] + T[1][1] * A[1][1]; - return result; } @@ -127,6 +123,12 @@ static void test() { uint64_t test_5 = math::fibonacci_sum::fiboSum(n, m); assert(test_5 == 322); std::cout << "Passed Test 5!" << std::endl; + + n=20; + m=30; + uint64_t test_6 = math::fibonacci_sum::fiboSum(n, m); + assert(test_6 == 14328); + std::court << "Passed Test 6!" << std::endl; } /**