Friday Scala Kata: Pascal’s Triangle

This week’s Scala Kata was suggested to me by Tim Dalton. For a given number, build Pascal’s Triangle as a List of Lists starting from the top down.

Here’s some examples to illustrate:

Given n = 1, then the result should be List(List(1))

Given n = 2, then the result should be List(List(1), List(1,1))

Given n = 4, then the result should be List(List(1),List(1,1), List(1,2,1), List(1,3,3,1))

And so on. Can you generate a triangle to the 14th row as in the above graphic? How about the 30th row?

You can leave a response, or trackback from your own site.

Facebook comments:

2 Responses to “Friday Scala Kata: Pascal’s Triangle”

  1. James Carr says:

    And yes, I realize I did not post this till Sunday. It’s been a busy weekend. ;)

  2. Geoff Reedy says:

    Here’s my solution: http://gist.github.com/434622

    Incidently, there’s an error in the graphic. The last row is {1,13,78,186,…,186,78,13,1} but it should be {1,13,78,286,…,286,78,13,1}

Leave a Reply

Subscribe to RSS Feed Follow me on Twitter!