http://www.perlmonks.org?node_id=440545


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.