Re: exercise in double number arithmetic

Liste des GroupesRevenir à cl forth 
Sujet : Re: exercise in double number arithmetic
De : nobody (at) *nospam* nowhere.invalid (Marc Olschok)
Groupes : comp.lang.forth
Date : 14. Jul 2024, 22:43:07
Autres entêtes
Message-ID : <v71gpb$jsug$1@solani.org>
References : 1
User-Agent : tin/2.4.4-20191224 ("Millburn") (Linux/2.6.33.4 (i686))
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.


Date Sujet#  Auteur
6 Jul 24 * exercise in double number arithmetic69Krishna Myneni
6 Jul 24 +* Re: exercise in double number arithmetic16Ahmed
7 Jul 24 i`* Re: exercise in double number arithmetic15Krishna Myneni
7 Jul 24 i +* Re: exercise in double number arithmetic13Ahmed
7 Jul 24 i i`* Re: exercise in double number arithmetic12Krishna Myneni
7 Jul 24 i i +* Re: exercise in double number arithmetic10Gerry Jackson
8 Jul 24 i i i`* Re: exercise in double number arithmetic9Krishna Myneni
10 Jul 24 i i i `* Re: exercise in double number arithmetic8Gerry Jackson
10 Jul 24 i i i  `* Re: exercise in double number arithmetic7dxf
10 Jul 24 i i i   +- Re: exercise in double number arithmetic1Krishna Myneni
10 Jul 24 i i i   `* Re: exercise in double number arithmetic5dxf
11 Jul 24 i i i    `* Re: exercise in double number arithmetic4Krishna Myneni
11 Jul 24 i i i     `* Re: exercise in double number arithmetic3minforth
12 Jul 24 i i i      `* Re: exercise in double number arithmetic2Krishna Myneni
12 Jul 24 i i i       `- Re: exercise in double number arithmetic1minforth
7 Jul 24 i i `- Re: exercise in double number arithmetic1Ahmed
7 Jul 24 i `- Re: exercise in double number arithmetic1minforth
6 Jul 24 +* Re: exercise in double number arithmetic3Ahmed
7 Jul 24 i`* Re: exercise in double number arithmetic2Krishna Myneni
7 Jul 24 i `- Re: exercise in double number arithmetic1Ahmed
7 Jul 24 +* Re: exercise in double number arithmetic14mhx
7 Jul 24 i`* Re: exercise in double number arithmetic13Ahmed
7 Jul 24 i +- Re: exercise in double number arithmetic1mhx
7 Jul 24 i +* Re: exercise in double number arithmetic2minforth
7 Jul 24 i i`- Re: exercise in double number arithmetic1Ahmed
7 Jul 24 i `* Re: exercise in double number arithmetic9Ahmed
7 Jul 24 i  `* Re: exercise in double number arithmetic8Ahmed
7 Jul 24 i   `* Re: exercise in double number arithmetic7mhx
7 Jul 24 i    +- Re: exercise in double number arithmetic1Ahmed
8 Jul 24 i    `* Re: exercise in double number arithmetic5Krishna Myneni
8 Jul 24 i     `* Re: exercise in double number arithmetic4Ahmed
8 Jul 24 i      +- Re: exercise in double number arithmetic1minforth
8 Jul 24 i      `* Re: exercise in double number arithmetic2Krishna Myneni
8 Jul 24 i       `- Re: exercise in double number arithmetic1Ahmed
14 Jul 24 `* Re: exercise in double number arithmetic35Marc Olschok
14 Jul 24  +- Re: exercise in double number arithmetic1Marc Olschok
15 Jul 24  +* Re: exercise in double number arithmetic12Krishna Myneni
15 Jul 24  i+* Re: exercise in double number arithmetic8minforth
15 Jul 24  ii`* Re: exercise in double number arithmetic7minforth
15 Jul 24  ii `* Re: exercise in double number arithmetic6Ahmed
15 Jul 24  ii  `* Re: exercise in double number arithmetic5minforth
15 Jul 24  ii   +- Re: exercise in double number arithmetic1minforth
15 Jul 24  ii   +- Re: exercise in double number arithmetic1Ahmed
15 Jul 24  ii   `* Re: exercise in double number arithmetic2albert
15 Jul 24  ii    `- Re: exercise in double number arithmetic1minforth
15 Jul 24  i+- Re: exercise in double number arithmetic1Anton Ertl
15 Jul 24  i+- Re: exercise in double number arithmetic1Gerry Jackson
31 Jul 24  i`- Re: exercise in double number arithmetic1Marc Olschok
15 Jul 24  `* Re: exercise in double number arithmetic21minforth
15 Jul 24   `* recursion (was: exercise in double number arithmetic)20Anton Ertl
15 Jul 24    +* Re: recursion10Marc Olschok
15 Jul 24    i`* Re: recursion9Ruvim
15 Jul 24    i +* Re: recursion5Gerry Jackson
15 Jul 24    i i+* Re: recursion2Gerry Jackson
16 Jul 24    i ii`- Re: recursion1Gerry Jackson
16 Jul 24    i i`* Re: recursion2Ruvim
16 Jul 24    i i `- Re: recursion1dxf
16 Jul 24    i +- Re: recursion1mhx
16 Jul 24    i `* Re: recursion2Ruvim
16 Jul 24    i  `- Re: recursion1Ruvim
16 Jul 24    `* Re: recursion9sjack
16 Jul 24     +- Re: recursion1sjack
16 Jul 24     +* Re: recursion4minforth
16 Jul 24     i`* Re: recursion3sjack
16 Jul 24     i `* Re: recursion2minforth
16 Jul 24     i  `- Re: recursion1mhx
17 Jul 24     `* Re: recursion3dxf
22 Jul 24      `* Re: recursion2Stephen Pelc
22 Jul 24       `- Re: recursion1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal