Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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.

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 avoiding work at the Monastery: (7)
As of 2016-06-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (326 votes). Check out past polls.