Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Lazy, fast, and I think it's correct.
use strict; use warnings; sub lazy_ham { my ($how_many) = @_; my @output_stream = (1); my @streams = map { my $base = $_; # All your base are belong to us my $index = 0; sub { if (@_) { return $base * $output_stream[$index]; } else { return $base * $output_stream[$index++]; } } } (2, 3, 5); for (1..$how_many) { # Find the lowest next item in the available streams my ($lowest) = sort {$a <=> $b} map {$_->('peek')} @streams; $_->('peek') == $lowest and $_->() for @streams; push(@output_stream, $lowest); } shift @output_stream; # Get rid of the seed 1 @output_stream; } print join(', ', lazy_ham(1000)), "\n";
2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 4 +0, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125 +, 128, 135, 144, 150, 160, 162, 180, 192, 200, 216, 225, 240, 243, 25 +0, 256, 270, 288, 300, 320, 324, 360, 375, 384, 400, 405, 432, 450, 4 +80, 486, 500, 512, 540, 576, 600, 625, 640, 648, 675, 720, 729, 750, +768, 800, 810, 864, 900, 960, 972, 1000, 1024, 1080, 1125, 1152, 1200 +, 1215, 1250, 1280, 1296, 1350, 1440, 1458, 1500, 1536, 1600, 1620, 1 +728, 1800, 1875,...

Caution: Contents may have been coded under pressure.

In reply to Re: Hamming Sequences and Lazy Lists by Roy Johnson
in thread Hamming Sequences and Lazy Lists by tall_man

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (9)
    As of 2014-07-31 04:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (244 votes), past polls