Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 116,628 of 117,927    |
|    Marc Olschok to All    |
|    Re: exercise in double number arithmetic    |
|    14 Jul 24 21:43:07    |
      From: nobody@nowhere.invalid              On Sat, 06 Jul 2024 22:20:45 Krishna Myneni wrote:       > I've been working on extending the kForth-64 User's Manual and, in       > particular, illustrating double length arithmetic, which, being one of       > the strengths of Forth, often does not get enough exposure. Here's an       > exercise which you can do using only standard Forth words.       >       > How many different ways can you choose 42 distinct objects, 21 at a       > time? This is "n choose k" or the binomial coefficent.              Yes, M*/ comes in handy for C(n,0) = 1 , C(n+1,k+1) = C(n,k)*n/k              42 21 binom d.       gives 538257874440              where              : binom ( n1 n2 -- nd ) \ n k --> C(n,k)        dup 0=        IF 2drop 1 s>d        ELSE 2dup 1- swap 1- swap binom 2swap m*/        THEN ;              Gforth SEE nicely replaced the original 'recurse' with 'binom' for       better readability.              --       M.O.              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca