[NTG-context] Code lua in a table

Fabrice Couvreur fabrice1.couvreur at gmail.com
Sat Jul 18 20:05:56 CEST 2020


Hello,
I want to display the values of Pascal's triangle in a table.
Unfortunately my knowledge of Lua is not sufficient to run this code.
Thank you.
Fabrice

\starttext

\startluacode
     function Binom(n,k)
       if k > n then
             return 0
       elseif (n == 0 or k == 0) then
             return 1
       else
             return (n*Binom(n-1,k-1))/k
     end
             context(Binom(n,k))
    end

    context.startxtable({"align={middle,lohi},
width=1.2cm,offset=0.8ex,bodyfont=9pt"})
    context.startxrow({"background=color,backgroundcolor=green"})
    for i = 0, 10 do
      for j = 0, i do
          context.startxcell()
            context(Binom(i,j))
          context.stopxcell()
      end
    end
    context.stopxrow()

\stopluacode

\stoptext
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20200718/d2b46d97/attachment.htm>


More information about the ntg-context mailing list