View/Edit #8495:Pascal

Switch to edit mode.

Name(s): Pascal
1:  "Pascals Triangle"
2:  "pascal(line #) Zero-indexed Integer"
3:  "Produces given line in Pascals Triangle, in which, starting with 1, produces each term as the sum of the two terms to the diagnal in the pervious line. As in:"
4:  "0 =         1"
5:  "1 =        1  1"
6:  "2 =      1   2  1"
7:  "3 =     1 3    3 1"
8:  "4 =   1  4  6   4  1"
9:  "5 =  1 5  10  10  5 1"
10: "6 = 1 6 15  20  15 6 1"
11: ""
12: "Mostly used for binomial expansion, as the coeffiecents of (x + y)^n are the numbers in the line indexed by n."
13: i = `args[1] ! ANY => 0'
14: i = typeof(i) == $INT ? i < 0 ? 0 | i | 0
15: pascal = {}
16: for r in [0..i]
17:   pascal = {@pascal, `$math_utils:factorial(i) / ($math_utils:factorial(r) * $math_utils:factorial(i - r)) ! ANY => 1'}
18: endfor
19: return pascal
20: "Last modified by Dax (#789) on Tue May  3 13:51:18 2005 MDT."

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Ezran (#3936)

You are not logged in.

[home | help | who | search | setup | code]