Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #46272

Rosetta: Lucas-Lehmer test

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Rosetta: Lucas-Lehmer test
Date 2016-03-29 05:10 +0000
Organization A noiseless patient Spider
Message-ID <ndd2nk$3lt$1@dont-email.me> (permalink)

Show all headers | View raw


Ocaml (based on the ingenious Pascal solution):

#load "nums.cma" ;;
open Num ;;

let n = ref (Int 1) in
  for exponent = 2 to 2500 do
    let s = ref (Int (if exponent=2 then 0 else 4)) in
      n := pred_num ((succ_num !n) */ Int 2) ;
      for i = 1 to exponent - 2 do
        s := mod_num (!s */ !s -/ Int 2) !n
      done ;
      if !s = Int 0 then
        Printf.printf "%d %!" exponent
  done ;;

 ===>
2 3 5 7 13 17 19 31 61 89 107 127 521 607 1279 2203 2281

Is it wise to try this in ANS Forth?


-- 
[T]he number of Jews killed there was 800,000,000.... [T]he Talmud makes it all
clear by informing us that the blood of the holocausted Jews ran to the sea in
a huge tidal wave that swept boulders in its path and was so deep that it
reached the nostrils of the Romans' horses.
nationalvanguard.org/2014/09/disillusioned-part-1/

Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Rosetta: Lucas-Lehmer test "WJ" <w_a_x_man@yahoo.com> - 2016-03-29 05:10 +0000
  Re: Rosetta: Lucas-Lehmer test Paul Rubin <no.email@nospam.invalid> - 2016-03-28 23:58 -0700

csiph-web