Sujet : Re: exercise in double number arithmetic
De : melahi_ahmed (at) *nospam* yahoo.fr (Ahmed)
Groupes : comp.lang.forthDate : 07. Jul 2024, 17:13:33
Autres entêtes
Organisation : novaBBS
Message-ID : <db3806e0ad371735050140c7a6b35f24@www.novabbs.com>
References : 1 2 3
User-Agent : Rocksolid Light
On Sun, 7 Jul 2024 15:41:54 (UTC), mhx wrote:
On Sun, 7 Jul 2024 11:24:35 (UTC), albert@spenarnc.xs4all.nl wrote:
>
How many different ways can you choose 42 distinct objects, 21 at a
time? This is "n choose k" or the binomial coefficent.
>
Please show your code.
[..]
2 \ For N M return "N OVER M " (N/M)
3 : CHS >R R@ - 1 R> 1+ 1 ?DO OVER I + I */ LOOP NIP ;
[..]
>
Really great!
>
FORTH> 42 21 CHS . 538257874440 ok
FORTH> 66 33 CHS . 7219428434016265740 ok
FORTH> 68 34 CHS . ( ... )
>
-marcel
Hi,
100 value N
create table N N * 2* cells allot
table N N * 2* cells erase
: table.init N 0 do 1. table i N * 2* cells + 2! loop ;
table.init
: table.calc N 1 do N 1 do table j 1 - N * i 1 - + 2* cells + 2@
table j 1 - N * i + 2* cells + 2@ d+
table j N * i + 2* cells + 2!
loop loop ;
table.calc
table 68 N * 34 + 2* cells + 2@ d. 28453041475240576740 ok
Wolfram alpha gives C(68,43) = 28453041475240576740
minforth version gives: 68 34 bcoef 28453041475240574976 ok (it is
different)
Ahmed