Calculates the first \e n Padovan numbers, of orders 0 through \e n - 1.

You're viewing an older version of this page (#5353). View the current version.

View versions (2)

Interface

#include <codecogs/maths/combinatorics/sequences/padovan_numbers_list.h>

using namespace Maths::Combinatorics::Sequences;

This function generates an array of the first n Padovan numbers (orders 0 through n - 1). The Padovan sequence is defined by the following recurrent formula:

$$P(i+1) = P(i-1) + P(i-2)$$
(1)

with initial values

$$P(0) = P(1) = P(2) = 1$$
(2)

Example 1

#include <codecogs/maths/combinatorics/sequences/padovan_numbers_list.h>
#include <iostream>
int main() {
  std::vector<int> result = Maths::Combinatorics::Sequences::padovan_numbers_list(11);
  std::cout << "Number of values: " << result.size() << std::endl;
  for (int i = 0; i < result.size(); i++)
    std::cout << result[i] << "  ";
  std::cout << std::endl;
  return 0;
}

Output:

Number of values: 11
1  1  1  2  2  3  4  5  7  9  12

Parameters

n
the number of Padovan numbers to generate

Returns

the first n Padovan numbers, of order 0 through n - 1

References

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

GPL Licence — free for non commercial use. See Licence details.