Pathologically Eclectic Rubbish Lister PerlMonks

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

by Roy Johnson (Monsignor)
 on Mar 18, 2005 at 20:20 UTC ( #440792=note: print w/replies, xml ) Need Help??

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

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.
• Comment on Re^3: Challenge: Another Infinite Lazy List

Replies are listed 'Best First'.
Re^4: Challenge: Another Infinite Lazy List
by demerphq (Chancellor) on Mar 19, 2005 at 09:06 UTC

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://440792]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2017-12-15 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What programming language do you hate the most?

Results (443 votes). Check out past polls.

Notices?