Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Challenge: Another Infinite Lazy List

by kelan (Deacon)
on Mar 18, 2005 at 18:20 UTC ( #440766=note: print w/ replies, xml ) Need Help??


in reply to Challenge: Another Infinite Lazy List

Here's my naive Haskell implementation, done without studying any of the others here, though after finishing and looking briefly through them, it is rather similar to some.

merge (x:xs) (y:ys) | x < y = x : merge xs (y:ys) | x > y = y : merge (x:xs) ys | x == y = x : merge xs ys supermerge (x:[]) = x supermerge (x:y:ys) = supermerge $ (merge x y) : ys multiples x = map (*x) [1..] multiplesFromList x = supermerge $ map (multiples) x limbic's_challenge = multiplesFromList [2,3,5]
I'm not sure how fast it is comparatively (especially since I'm running it in Hugs), but I can get a million items in about 20 seconds.


Comment on Re: Challenge: Another Infinite Lazy List
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-09-17 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (95 votes), past polls