Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- makeatletter
- newcommandbinomialCoefficient[2]{%
- % Store values
- c@pgf@counta=#1% n
- c@pgf@countb=#2% k
- %
- % Take advantage of symmetry if k > n - k
- c@pgf@countc=c@pgf@counta%
- advancec@pgf@countc by-c@pgf@countb%
- ifnumc@pgf@countb>c@pgf@countc%
- c@pgf@countb=c@pgf@countc%
- fi%
- %
- % Recursively compute the coefficients
- c@pgf@countc=1% will hold the result
- c@pgf@countd=0% counter
- pgfmathloop% c -> c*(n-i)/(i+1) for i=0,...,k-1
- ifnumc@pgf@countd<c@pgf@countb%
- multiplyc@pgf@countc byc@pgf@counta%
- advancec@pgf@counta by-1%
- advancec@pgf@countd by1%
- dividec@pgf@countc byc@pgf@countd%
- repeatpgfmathloop%
- thec@pgf@countc%
- }
- makeatother
- begin{document}
- begin{tikzpicture}
- foreach n in {0,...,15} {
- foreach k in {0,...,n} {
- node at (k-n/2,-n) {$binomialCoefficient{n}{k}$};
- }
- }
- end{tikzpicture}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement