Pathologically Eclectic Rubbish Lister PerlMonks

### Re^2: Challenge: Another Infinite Lazy List

by demerphq (Chancellor)
 on Mar 18, 2005 at 16:14 UTC ( #440727=note: print w/replies, xml ) Need Help??

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

Am I right in thinking you are basically doing the same thing as my make_sub2() implementation but rotating the data (Ie, i have two array of N elements, you have N arrays of 2 elements)?

---
demerphq

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

Replies are listed 'Best First'.
Re^3: Challenge: Another Infinite Lazy List
by Roy Johnson (Monsignor) on Mar 18, 2005 at 20:20 UTC
It looks like we're working with the same data, though I don't think we're doing the same thing with it to get our results. Here's mine explained: Each stream stores its base (2, 3, or 5) and the multiplier last used with that base to generate an output element. To generate the next element of the sequence, I check what the next output would be from each stream (multiply the base by the last multiplier + 1) and choose the lowest of those, incrementing the multiplier of each stream that would give me that lowest number. That's it.

Caution: Contents may have been coded under pressure.

Hmm. My variation uses the @v array to store the next value that would come from a given stream, and the @f array to store what value a given stream is incremented by when a value is "popped" from it. When it comes time to return the next value in the sequence the lowest value available is "popped" from the streams. If it could have also come from a stream with a smaller factor it is ignored and the process repeats otherwise the popped value is returned.

As far as I can tell this is basically the same thing as yours, except you multiply and I increment, and the way we handle dupes is slighlty different but the principle is the same. Its just interesting to me, I find the way identical algorithms can look so different at first glance to be fascinating.

---
demerphq

Create A New User
Node Status?
node history
Node Type: note [id://440727]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2018-02-25 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When it is dark outside I am happiest to see ...

Results (315 votes). Check out past polls.

Notices?