|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Re^4: Challenge: Another Infinite Lazy Listby tlm (Prior) |
| on Mar 18, 2005 at 22:18 UTC ( #440815=note: print w/ replies, xml ) | Need Help?? |
|
You're right. I misread your original post. What threw me off was the mention of streams. In the solution you present (which is indeed entirely different from merging lists), using lazy lists seems forced to me, since their properties don't get you anything that you couldn't get very easily and directly with grep and the '..' operator: Thanks for pointing out the Streams module. It does some very nice things which I think I should incorporate in my stab at implementing lazy lists. Update: Oh, yes. There's memoization in Stream.pm, all right; it's just done very discreetly (and elegantly, IMO):
BTW the execution time of my merged-lists solution is not growing anywhere nearly as fast as the formula you gave (not that it matters a whole lot, but I give the stats below if anyone's interested). Still, the gcd-based solution is noticeably faster; whether this is the result of the fact that most of its heavy lifting (the gcd calculation) is done by a C routine, or something more fundamental is not yet clear to me. the lowliest monk
OK, here are the stats for the merged-lists solution. All the runs were performed with arguments consisting of a prefix of the list primes from 2 to 37, with N=2000 throughout. The formula mentioned below is the one given by tall man here.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||