DAPPLE Example: pascal

Source code:

// pascal -- pascal's triangle // written using the Data-Parallel Programming Library for Education (DAPPLE) // // David Kotz 1994 // $Id: pascal.cc,v 2.13 94/09/29 12:18:16 dfk Exp $ #include #include #include "dapple.h" const int N = 10; // number of rows (and columns) const intVector VP(N, Identity); // which VP am I? useful for VP-specific math int main(int argc, char **argv) { intVector arow(N); ifp (VP == 0) { // only the left one will be 1 initially arow = 1; cout << arow << endl; } else arow = 0; // to each element, add the element to the left for (int i = 1; i <= N-1; i++) { arow += shift(arow, 1); ifp (VP <= i) cout << arow << endl; } return(0); }

Demonstration:

pascal 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1