12 #ifndef ECL_GEOMETRY_PASCALS_HPP_ 13 #define ECL_GEOMETRY_PASCALS_HPP_ 19 #include <ecl/config/macros.hpp> 20 #include <ecl/containers/array.hpp> 21 #include <ecl/formatters/common.hpp> 22 #include <ecl/formatters/number.hpp> 63 virtual ~PascalsTriangle() {};
68 typedef typename Array<int,(N+2)*(N+1)/2>::const_iterator const_iterator;
69 const_iterator begin(
unsigned int index = 0)
const;
70 const_iterator end(
unsigned int index = 0)
const;
75 template <
typename OutputStream,
int PowerN>
76 friend OutputStream& operator<<(OutputStream &ostream, const PascalsTriangle<PowerN> &triangle);
79 Array<int,(N+2)*(N+1)/2> coefficients;
107 virtual ~PascalsTriangle() {};
120 const_iterator begin(
unsigned int index = 0)
const;
128 const_iterator end(
unsigned int index = 0)
const;
133 template <
typename OutputStream>
134 friend OutputStream& operator<<(OutputStream &ostream, const PascalsTriangle<3> &triangle);
137 Array<int,10> coefficients;
166 virtual ~PascalsTriangle() {};
179 const_iterator begin(
unsigned int index = 0)
const;
187 const_iterator end(
unsigned int index = 0)
const;
192 template <
typename OutputStream>
193 friend OutputStream& operator<<(OutputStream &ostream, const PascalsTriangle<5> &triangle);
196 Array<int,21> coefficients;
210 for (
int i = N+1; i > 0; --i ) {
211 for (
int j = 0; j < i; ++j ) {
212 if ( ( i == N+1 ) || ( j == 0 ) ) {
213 coefficients[counter] = 1;
215 coefficients[counter] = coefficients[counter-1] + coefficients[counter-(i+1)];
232 for (
unsigned int i = 0; i < index; ++i ) {
233 coeff_index += N+1-i;
235 return const_iterator( &coefficients[coeff_index] );
247 for (
unsigned int i = 0; i <= index; ++i ) {
248 coeff_index += N+1-i;
251 return const_iterator( (&coefficients[coeff_index])+1);
270 template <
typename OutputStream,
int PowerN>
271 OutputStream& operator << ( OutputStream &ostream, const PascalsTriangle<PowerN> &triangle)
275 for (
int i = PowerN+1; i > 0; --i ) {
276 for (
int j = 0; j < i; ++j ) {
277 ostream << format(triangle.coefficients[counter]) <<
" ";
296 template <
typename OutputStream>
297 OutputStream& operator << ( OutputStream &ostream, const PascalsTriangle<3> &triangle)
301 for (
int i = 4; i > 0; --i ) {
302 for (
int j = 0; j < i; ++j ) {
303 ostream << format(triangle.coefficients[counter]) <<
" ";
322 template <
typename OutputStream>
323 OutputStream& operator << ( OutputStream &ostream, const PascalsTriangle<5> &triangle)
327 for (
int i = 6; i > 0; --i ) {
328 for (
int j = 0; j < i; ++j ) {
329 ostream << format(triangle.coefficients[counter]) <<
" ";
const int * const_iterator
const_iterator end(unsigned int index=0) const
Iterator generator for diagonals of pascals triangle [end].
const_iterator begin(unsigned int index=0) const
Iterator generator for diagonals of pascals triangle [begin].
Array< int,(N+2)*(N+1)/2 >::const_iterator const_iterator
PascalsTriangle()
Default constructor.