Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Using the subs whose definitions I posted in Re: Hamming Sequences and Lazy Lists, the following:

my $ones; $ones = ll_new(1, memoize(sub { $ones })); my $integers; $integers = ll_new(0, memoize(sub { ll_add($ones, $integers) })); sub multiples { my $n = shift; return ll_map( sub { $n * $_[0] }, $integers ); } sub challenge { return [] unless @_; my $x = shift; my $out; $out = merge( multiples($x), challenge(@_) ); return $out; } my @first_200 = take( 200, challenge(2, 3, 5) ); print "@first_200\n";
prints this out:
0 2 3 4 5 6 8 9 10 12 14 15 16 18 20 21 22 24 25 26 27 28 30 32 33 34 +35 36 38 39 40 42 44 45 46 48 50 51 52 54 55 56 57 58 60 62 63 64 65 +66 68 69 70 72 74 75 76 78 80 81 82 84 85 86 87 88 90 92 93 94 95 96 +98 99 100 102 104 105 106 108 110 111 112 114 115 116 117 118 120 122 + 123 124 125 126 128 129 130 132 134 135 136 138 140 141 142 144 145 +146 147 148 150 152 153 154 155 156 158 159 160 162 164 165 166 168 1 +70 171 172 174 175 176 177 178 180 182 183 184 185 186 188 189 190 19 +2 194 195 196 198 200 201 202 204 205 206 207 208 210 212 213 214 215 + 216 218 219 220 222 224 225 226 228 230 231 232 234 235 236 237 238 +240 242 243 244 245 246 248 249 250 252 254 255 256 258 260 261 262 2 +64 265 266 267 268 270 272

the lowliest monk


In reply to Re: Challenge: Another Infinite Lazy List by tlm
in thread Challenge: Another Infinite Lazy List by Limbic~Region

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-03-29 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found