help with prime pairs code

Salih Dincer salihdb at hotmail.com
Wed Feb 19 02:25:03 UTC 2025


On Tuesday, 18 February 2025 at 22:45:39 UTC, Jabari Zakiya wrote:
>
> I'm bringing attention to this issue as it might improve D.
>
> It has to do with the fastest way to remove elements in one 
> array|list from another.
>
> It concerns the code in this thread to generate the prime pairs 
> of n.
>
> In the code I have two arrays, `lhr` and `lhr_del`, and want to 
> remove|delete the elements in `lhr_del` from `lhr`.
>

Many parts of the core code can be optimized. Since I don't have 
much time right now, I only saw 1 improvement. Below the GCD 
filter will give the same list (lhr[]).

```d
   uint[] lhr;// = iota(3, ndiv2, 2).filter!(e => gcd(e, n) == 
1).array;/*
   lhr.reserve(cast(ulong)log(cast(double)n)/2);
   for (uint i = 3; i < ndiv2; i += 2)
   {
     if (i % 3 != 0 && i % 5 != 0)
     {
       lhr ~= i;
     }
   }//*/
```

SDB at 79



More information about the Digitalmars-d-learn mailing list