Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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)?


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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://440727]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2015-10-10 20:41 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (258 votes), past polls