Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Challenge: Another Infinite Lazy List

by tlm (Prior)
on Mar 17, 2005 at 21:05 UTC ( #440542=note: print w/ replies, xml ) Need Help??


in reply to Challenge: Another Infinite Lazy List

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


Comment on Re: Challenge: Another Infinite Lazy List
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://440542]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2015-07-03 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls