Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Challenge: Another Infinite Lazy List

by Joost (Canon)
on Mar 17, 2005 at 21:14 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://440545]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-24 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found