go ahead... be a heretic | |
PerlMonks |
Re: Hamming Sequences and Lazy Listsby Roy Johnson (Monsignor) |
on Mar 18, 2005 at 00:56 UTC ( [id://440602]=note: print w/replies, xml ) | Need Help?? |
I offer one last solution, which addresses an issue raised in Re: Functional perl please: "(we exclude "solutions" which must store the entire sequence in a large array and the like)". My previous solutions did store the array, because they returned it as one piece.
This sub is an iterator, returning the next in the sequence on each call. It maintains only the portion of the output stream that it needs to continue generating. I used Math::BigInt so I could get into interesting numbers. It takes several minutes to find the 100000th or so in the series. But if you're interested, #100001 through 100005 are with 5446 elements in the queue.
Caution: Contents may have been coded under pressure.
In Section
Seekers of Perl Wisdom
|
|