# Sample Chapel Exercises (CCSC-CP 2014 Tutorial)

Feel free to follow your interests in exploring Chapel, but here are some suggestions. For examples of Chapel syntax, refer to the cheat sheet and to examples.chpl (html version). You can also refer to our tutorials:

and the slides on the workshop main page.

Remember that to compile and run, you can do the following:

```  chpl -o hello hello.chpl
./hello
```

#### Suggestions for hands-on session:

1. Write some of the simple example programs from the slides ("Hello World", summing numbers 1 to 100, etc)
2. Write a parallel version of bubble sort: Repeatedly compare each even-indexed element with its successor and then each odd-indexed element with its successor. After n repetitions of this, the array should be sorted. examples.chpl (html version) gives a serial implementation.
3. Implement binary search.
4. Use scan to compute an array of factorials (0!, 1!, 2!, 3!, ...)
5. Use scan to compute an array of powers of 3 (1, 3, 9, 27, 81, ...)
6. Use the previous two parts to compute the (partial) sum of a Taylor series such as
```ex=1+x+x2/2! + x3/3! + ... + xi/i! + ...
```
7. Define a node class and use it to make a linked list. (nil is the name of a null reference in Chapel.) Write functions for inserting, removing, printing the list, etc.
8. Write a custom reduction to identify the 2nd smallest value. (The sample custom reduction is in sampleReduction.chpl (html version).) What about the kth smallest?
9. Write a custom reduction to compute a histogram from an array of 0s, 1s, and 2s.
10. Use a reduction to compute the index where the pivot of quicksort will be placed, i.e. the number of values smaller than the pivot value.