home bbs files messages ]

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,604 of 117,927   
   albert@spenarnc.xs4all.nl to krishna.myneni@ccreweb.org   
   Re: exercise in double number arithmetic   
   07 Jul 24 13:24:35   
   
   In article ,   
   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.   
   >   
   >Please show your code.   
      
   It is in the special function screen:   
    0 ( CHS TRI PYR SQ CUB FIB               ) \ AvdH B8jan21   
    2 \ For N M return "N OVER M " (N/M)   
    3 : CHS >R  R@ - 1 R> 1+ 1 ?DO   OVER I + I */ LOOP NIP ;   
    4 \ '(./.) ALIAS CHS   
    5   
    6 \ For x return its TRIANGLE, number   
    7 : TRI    DUP 1+ * 2/ ;   
    8 \ For x return its PYRAMIDAL number   
    9 ( : PYR ; )   
    10 \ For x return its SQUARE  number   
    11 : SQ DUP * ;   
    12 \ For x return its CUBE number   
    13 : CUB DUP DUP * * ;   
    14 \ For x return the  xth  Fibonacci  .   
    15 : FIB   >R 0 1 R> 0 ?DO SWAP OVER + LOOP DROP ;   
      
    S[ ] OK 42 21 chs   
    S[ 538257874440 ] OK   
      
   >   
   >--   
   >Krishna Myneni   
   >   
   --   
   Don't praise the day before the evening. One swallow doesn't make spring.   
   You must not say "hey" before you have crossed the bridge. Don't sell the   
   hide of the bear until you shot it. Better one bird in the hand than ten in   
   the air. First gain is a cat purring.            - the Wise from Antrim -   
      
   --- 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