|
We're glad you came by, but you might find what you're looking for elsewhere. TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it. Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope. |
Returns the Rth row of Pascal's triangle
R - The requested row of Pascal's triangle
Ans - Contains the row, as a list
R, Ans
TI-83/84/+/SE
:{1
:If R
:2^Rbinompdf(R,.5This routine uses the binompdf( command to generate a row of Pascal's triangle. Each number in Pascal's triangle is gotten by adding the two numbers above it, like such:
....1
1 1
1 2 1
1 3 3 1
1 4 6 4 1By tradition, the rows are numbered starting with 0, so that 1 is actually the "zeroth" row, while the first row is 1 1.
The binompdf( method of calculating rows of Pascal's triangle relies on one of its many properties: if a coin is flipped R times, then the number of heads (or the number of tails) flipped is distributed in the same way as the rows of the pascal's triangle, and the binompdf( command computes precisely such probabilities.
We multiply by 2^R to convert the probabilities to whole numbers. Unfortunately, binompdf( doesn't work for the R=0 case, so we make it a special case (if you never need to compute this case, you can omit this, turning the routine into a single statement).
Another way to get the number is to use the nCr command. N nCr K returns the Kth element of the Nth row (here, K is also numbered starting from 0). This can be done using the following line of code:
:seq(R nCr K,K,0,RThis goes through a line a gets every value of R nCr K and puts all results into a list. This routine is smaller than the one above, but is also slower.
Error Conditions
- ERR:DOMAIN is thrown if R is negative, or not a whole number.
Related Routines
If one outputs Pascal's triangle to a graph with even numbers as white dots and odd numbers as black dots, the outcome will be Sierpinski's triangle. Another way to generate Sierpinski's triangle is found below:
.