Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Challenge: Another Infinite Lazy List

by Joost (Canon)
on Mar 17, 2005 at 21:14 UTC ( #440545=note: print w/ replies, xml ) Need Help??


in reply to Challenge: Another Infinite Lazy List

I suspect this isn't bulletproof, but it appears to work for the given example:

update2: after some thinking, I'm convinced it's ok.

#!perl -w use strict; my $end = shift || 40; my $i = merge_multiple(@ARGV ? @ARGV : (2,3,5)); print $i->(),"\n" for 1 .. $end; sub merge_multiple { my $last = 0;
my %vals = map { $_ => $_ } sort { $a <=> $b } @_;
my %vals = map { $_ => $_ } @_; sub { for (keys %vals) { $vals{$_} += $_ if $vals{$_} <= $last; } my ($r) = sort { $a <=> $b } values %vals; $last = $r; } }
Cheers. update: removed legacy sort, wasn't used anyway.


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-09-22 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (179 votes), past polls