What is a Pascal Triangle? For the 1% of the mathematically inclined it is just "a triangular array of the binomial coefficients". For us, the 99% of mere mortals, we know a Pascal Triangle when we see it:
This week's exercise is to generate a Pascal Triangle two ways:
- recursively, with a method that calls itself again and again.
- iteratively, a.k.a. non recursively (go figure), carry forward your results as you compute the triangle.
If dutifully inclined spend a minute to think about the costs and benefits of each approach.
Pat in the Back: Google how to implement tail recursion in Ruby (or language of your choice). See if it can be applied to your recursive code.
Standing Ovation: Take a Pascal Triangle, will travel. Can you think of other ways to use PTs in a freaky weird way? One idea pops to mind, use Pascal Triangles + graphics gem to create fractals (hint: Sierpinski).