All of these solutions except F# and Raku end up calling GMP for this
(which uses Miller-Rabin; so does J). I think F# uses the following .NET
library, while Raku appears to eventually call an npm package
jsbi-is-prime?

https://github.com/Open-NET-Libraries/Open.Numeric.Primes/blob/master/source/MillerRabin.cs

Even so, it's not particularly fast: I timed the Julia version at 15s to
solve the base task. Clearly the limits are chosen to be moderately
taxing for the fastest libraries out there; anything without years of
optimization effort is left behind.

Adding x: to your version runs out of memory for some reason, but it
looks like the following would probably finish in half an hour or so.

{{1+I. 1 p:y#.x:|.+./\.=i.1000}}&.> 2+i.15

Marshall

On Tue, Jan 25, 2022 at 05:52:40AM -0500, Raul Miller wrote:
> http://www.rosettacode.org/wiki/Repunit_primes
> 
> Conceptually, this task might be tackled using an expression like
> 
>    ":@I. 1 p:(2+i.15) #."0 1/|.+./\.=i.1000
> 
> However, some of the numbers being tested for primality here are
> rather large. Even the base 2 numbers reach 300 digits, and the base
> 16 numbers reach 1200 digits:
> 
>    #":2x#.1000#1
> 302
>    #":16x#.1000#1
> 1203
> 
> So... how would we approach this in J?
> 
> Thanks,
> 
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to