Deutsch   English   Français   Italiano  
<db3806e0ad371735050140c7a6b35f24@www.novabbs.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: melahi_ahmed@yahoo.fr (Ahmed)
Newsgroups: comp.lang.forth
Subject: Re: exercise in double number arithmetic
Date: Sun, 7 Jul 2024 16:13:33 +0000
Organization: novaBBS
Message-ID: <db3806e0ad371735050140c7a6b35f24@www.novabbs.com>
References: <v6c8v0$3usoe$1@dont-email.me> <nnd$190e18f3$02eb8e44@e16a1d647fb55d93> <8da4b31b5cb3f13d9c296278d6821e6f@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="2479464"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="hogn68ACS2mVV0PcPkBzD/3kIXL71Lu5zlxJ/QczJJE";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$LNlM5Wf7XVZuUCcl/BkTGelgbMo5FiTAfbln1FIPb8qYTSaq8ohkC
X-Rslight-Posting-User: cdd77cd46f5cefdf617b921703a970831cf47f35
Bytes: 2163
Lines: 47

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