Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Challenge: Another Infinite Lazy List

by Roy Johnson (Monsignor)
on Mar 18, 2005 at 20:20 UTC ( [id://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.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found