Prime number

Greatsam4sure greatsam4sure at gmail.com
Thu Aug 2 14:37:56 UTC 2018


On Thursday, 2 August 2018 at 09:35:20 UTC, Cym13 wrote:
> On Thursday, 2 August 2018 at 08:30:05 UTC, Greatsam4sure wrote:
>> I know D is very powerful from my little experience. What is 
>> the idiomatic way to get prime numbers say from 1-30 without 
>> using loops(outer and inner loop). Can map, filter, fold etc 
>> in algorithm be use.  Pls show some code with chain call.
>>
>> I can easily achieve even numberd and odd numbers using 
>> filter. But prime numbers I have to use 2loops.
>>
>> I will appreciate any help,just a newbie in D
>
> Denis' answer is good but I'd like to add that the idiomatic D 
> solution is to use whatever tool is the most adequate to solve 
> the issue. If two loops is more natural it wouldn't make much 
> sense to force yourself to use range functions (even though I'd 
> obviously understand that stand to learn to use them).



Thanks, I like the idea of using helper function from algorithm 
module to do the magic instead of loops.  I want to know How To 
optimize it to efficient.
I will appreciate any help.
I will also appreciate a link to a comprehensive tutorial on the 
algorithm module. The documentation did not give me all the help 
I needed



More information about the Digitalmars-d-learn mailing list