pascals_triangle.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include "../../include/ecl/geometry/pascals_triangle.hpp"
14 
15 /*****************************************************************************
16 ** Namespaces
17 *****************************************************************************/
18 
19 namespace ecl {
20 
21 /*****************************************************************************
22 ** Implementation [PascalsTriangle<3>]
23 *****************************************************************************/
25  coefficients << 1,1,1,1,
26  1,2,3,
27  1,3,
28  1;
29 }
30 
32  int coeff_index = 0;
33  for (unsigned int i = 0; i < row_index; ++i ) {
34  coeff_index += 3+1-i;
35  }
36  return const_iterator( &coefficients[coeff_index] );
37 }
38 PascalsTriangle<3>::const_iterator PascalsTriangle<3>::end(unsigned int row_index) const {
39  int coeff_index = 0;
40  for (unsigned int i = 0; i <= row_index; ++i ) {
41  coeff_index += 3+1-i;
42  }
43  coeff_index -= 1; // dont want to call beyond the array limit.
44  return const_iterator( (&coefficients[coeff_index])+1 );
45 }
46 
47 
48 /*****************************************************************************
49 ** Implementation [PascalsTriangle<5>]
50 *****************************************************************************/
52  coefficients << 1,1,1,1,1,1,
53  1,2,3,4,5,
54  1,3,6,10,
55  1,4,10,
56  1,5,
57  1;
58 }
59 
61  int coeff_index = 0;
62  for (unsigned int i = 0; i < row_index; ++i ) {
63  coeff_index += 5+1-i;
64  }
65  return const_iterator( &coefficients[coeff_index] );
66 }
67 PascalsTriangle<5>::const_iterator PascalsTriangle<5>::end(unsigned int row_index) const {
68  int coeff_index = 0;
69  for (unsigned int i = 0; i <= row_index; ++i ) {
70  coeff_index += 5+1-i;
71  }
72  coeff_index -= 1; // dont want to call beyond the array limit.
73  return const_iterator( (&coefficients[coeff_index])+1 );
74 }
75 
76 
77 } // namespace ecl
ecl::PascalsTriangle::coefficients
Array< int,(N+2) *(N+1)/2 > coefficients
Definition: pascals_triangle.hpp:93
ecl::PascalsTriangle< 3 >::const_iterator
Array< int, 10 >::const_iterator const_iterator
Utilise the array's iterator for parsing the triangle.
Definition: pascals_triangle.hpp:115
ecl::PascalsTriangle::PascalsTriangle
PascalsTriangle()
Default constructor.
Definition: pascals_triangle.hpp:214
ecl::PascalsTriangle< 5 >::const_iterator
Array< int, 21 >::const_iterator const_iterator
Utilise the array's iterator for parsing the triangle.
Definition: pascals_triangle.hpp:174
ecl::PascalsTriangle::begin
const_iterator begin(unsigned int index=0) const
Iterator generator for diagonals of pascals triangle [begin].
Definition: pascals_triangle.hpp:236
ecl
Embedded control libraries.
ecl::PascalsTriangle::const_iterator
Array< int,(N+2) *(N+1)/2 >::const_iterator const_iterator
Utilise the array's iterator for parsing the triangle.
Definition: pascals_triangle.hpp:77
ecl::PascalsTriangle::end
const_iterator end(unsigned int index=0) const
Iterator generator for diagonals of pascals triangle [end].
Definition: pascals_triangle.hpp:251


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:39