TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of the N-bonacci series. More...
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | math |
for assert | |
namespace | n_bonacci |
Functions for the N-bonacci implementation. | |
Functions | |
std::vector< uint64_t > | math::n_bonacci::N_bonacci (const uint64_t &n, const uint64_t &m) |
Finds the N-Bonacci series for the n parameter value and m parameter terms. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Implementation of the N-bonacci series.
In general, in N-bonacci sequence, we generate sum of preceding N numbers from the next term.
For example, a 3-bonacci sequence is the following: 0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81 In this code we take N and M as input where M is the number of terms to be printed of the N-bonacci series
Definition in file n_bonacci.cpp.
int main | ( | void | ) |
Main function.
Definition at line 104 of file n_bonacci.cpp.
std::vector< uint64_t > math::n_bonacci::N_bonacci | ( | const uint64_t & | n, |
const uint64_t & | m ) |
Finds the N-Bonacci series for the n
parameter value and m
parameter terms.
n | is in the N-Bonacci series |
m | is the number of terms in the N-Bonacci sequence |
we initialise the (n-1)th term as 1 which is the sum of preceding N zeros
similarily the sum of preceding N zeros and the (N+1)th 1 is also 1
Definition at line 40 of file n_bonacci.cpp.
|
static |
Self-test implementations.
Definition at line 69 of file n_bonacci.cpp.