$pascal(N,[c])

By Firstmate on Mar 06, 2009

This simple identifier return's the Nth row for Pascals Triangle. If you want, there's an option 2nd parameter, that returns the C column in that row.

For those that don't know, Pascal's Triangle is an arrangement of numbers in a triangle. Here's an example of the triangle.

Image

alias pascal {
  var %r $calc($1 + 1), %y $1, %p, %t = 0, %x = 1
  while (%t < %r) {
    if (%t == 0 || %t == %r) { %p = %p 1 | %x = 1 }
    else {
      %p = %p $calc(%x * ((%r - %t) / %t))
      %x = $calc(%x * ((%r - %t) / %t))
    }  
    inc %t
  }
  if ($2 <= %r) {
    if ($2) { return $gettok(%p,$2,32) }
    else { return %p }
  }
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.