Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^5: Challenge: Another Infinite Lazy List

by tall_man (Parson)
on Mar 19, 2005 at 00:38 UTC ( #440837=note: print w/replies, xml ) Need Help??

in reply to Re^4: Challenge: Another Infinite Lazy List
in thread Challenge: Another Infinite Lazy List

There are a couple of advantages of the lazy list form over grep.

1) You can get an exact number of values out of the sequence without having to know the maximum number range in advance. For example, your sample code produces only 36 values, not the expected 50. You would have to feed it a range up to 273 to get a full 50.

2) You could extract and print values in a loop without building a large result array (a map in void context could do the same, I suppose).

My estimates for timing were rough back-of-the-envelope calculations, so I'm not surprised that they are a bit off. There are a number of things I didn't take into account, such as the overlaps where more than one prime is a factor, and the fact that more numbers are eliminated with more factors, so you have to search bigger integers to finish the list. Thanks for your timing tests.

Math::Pari is a highly optimized math engine, so I'm not too surpised that single gcd checks beat multiple merges. But if you start with primes at 101 and above instead, the merge algorithm will win.

  • Comment on Re^5: Challenge: Another Infinite Lazy List

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://440837]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-02-24 22:09 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (363 votes). Check out past polls.