Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. makeatletter
  2. newcommandbinomialCoefficient[2]{%
  3. % Store values
  4. c@pgf@counta=#1% n
  5. c@pgf@countb=#2% k
  6. %
  7. % Take advantage of symmetry if k > n - k
  8. c@pgf@countc=c@pgf@counta%
  9. advancec@pgf@countc by-c@pgf@countb%
  10. ifnumc@pgf@countb>c@pgf@countc%
  11. c@pgf@countb=c@pgf@countc%
  12. fi%
  13. %
  14. % Recursively compute the coefficients
  15. c@pgf@countc=1% will hold the result
  16. c@pgf@countd=0% counter
  17. pgfmathloop% c -> c*(n-i)/(i+1) for i=0,...,k-1
  18. ifnumc@pgf@countd<c@pgf@countb%
  19. multiplyc@pgf@countc byc@pgf@counta%
  20. advancec@pgf@counta by-1%
  21. advancec@pgf@countd by1%
  22. dividec@pgf@countc byc@pgf@countd%
  23. repeatpgfmathloop%
  24. thec@pgf@countc%
  25. }
  26. makeatother
  27.  
  28. begin{document}
  29. begin{tikzpicture}
  30. foreach n in {0,...,15} {
  31. foreach k in {0,...,n} {
  32. node at (k-n/2,-n) {$binomialCoefficient{n}{k}$};
  33. }
  34. }
  35. end{tikzpicture}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement