Show More
@@ -82,7 +82,7 b" fileline = '" | |||
|
82 | 82 | annotateline = ' |
|
83 | 83 | <tr class="parity{parity}"> |
|
84 | 84 | <td class="linenr"> |
|
85 | <a href="{url}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}#{targetline}" | |
|
85 | <a href="{url}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}#l{targetline}" | |
|
86 | 86 | title="{node|short}: {desc|escape|firstline}">{author|user}@{rev}</a> |
|
87 | 87 | </td> |
|
88 | 88 | <td class="lineno"> |
@@ -70,7 +70,7 b' filelogentry = filelogentry.tmpl' | |||
|
70 | 70 | annotateline = ' |
|
71 | 71 | <tr class="parity{parity}"> |
|
72 | 72 | <td class="annotate"> |
|
73 | <a href="{url}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}#{targetline}" | |
|
73 | <a href="{url}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}#l{targetline}" | |
|
74 | 74 | title="{node|short}: {desc|escape|firstline}">{author|user}@{rev}</a> |
|
75 | 75 | </td> |
|
76 | 76 | <td class="source"><a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</td> |
@@ -273,224 +273,224 b' hgweb fileannotate, html' | |||
|
273 | 273 | |
|
274 | 274 | <tr class="parity0"> |
|
275 | 275 | <td class="annotate"> |
|
276 | <a href="/annotate/853dcd4de2a6/primes.py#1" | |
|
276 | <a href="/annotate/853dcd4de2a6/primes.py#l1" | |
|
277 | 277 | title="853dcd4de2a6: a">test@0</a> |
|
278 | 278 | </td> |
|
279 | 279 | <td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td> |
|
280 | 280 | </tr> |
|
281 | 281 | <tr class="parity1"> |
|
282 | 282 | <td class="annotate"> |
|
283 | <a href="/annotate/853dcd4de2a6/primes.py#2" | |
|
283 | <a href="/annotate/853dcd4de2a6/primes.py#l2" | |
|
284 | 284 | title="853dcd4de2a6: a">test@0</a> |
|
285 | 285 | </td> |
|
286 | 286 | <td class="source"><a href="#l2" id="l2"> 2</a> </td> |
|
287 | 287 | </tr> |
|
288 | 288 | <tr class="parity0"> |
|
289 | 289 | <td class="annotate"> |
|
290 | <a href="/annotate/853dcd4de2a6/primes.py#3" | |
|
290 | <a href="/annotate/853dcd4de2a6/primes.py#l3" | |
|
291 | 291 | title="853dcd4de2a6: a">test@0</a> |
|
292 | 292 | </td> |
|
293 | 293 | <td class="source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></td> |
|
294 | 294 | </tr> |
|
295 | 295 | <tr class="parity1"> |
|
296 | 296 | <td class="annotate"> |
|
297 | <a href="/annotate/853dcd4de2a6/primes.py#4" | |
|
297 | <a href="/annotate/853dcd4de2a6/primes.py#l4" | |
|
298 | 298 | title="853dcd4de2a6: a">test@0</a> |
|
299 | 299 | </td> |
|
300 | 300 | <td class="source"><a href="#l4" id="l4"> 4</a> </td> |
|
301 | 301 | </tr> |
|
302 | 302 | <tr class="parity0"> |
|
303 | 303 | <td class="annotate"> |
|
304 | <a href="/annotate/853dcd4de2a6/primes.py#5" | |
|
304 | <a href="/annotate/853dcd4de2a6/primes.py#l5" | |
|
305 | 305 | title="853dcd4de2a6: a">test@0</a> |
|
306 | 306 | </td> |
|
307 | 307 | <td class="source"><a href="#l5" id="l5"> 5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></td> |
|
308 | 308 | </tr> |
|
309 | 309 | <tr class="parity1"> |
|
310 | 310 | <td class="annotate"> |
|
311 | <a href="/annotate/853dcd4de2a6/primes.py#6" | |
|
311 | <a href="/annotate/853dcd4de2a6/primes.py#l6" | |
|
312 | 312 | title="853dcd4de2a6: a">test@0</a> |
|
313 | 313 | </td> |
|
314 | 314 | <td class="source"><a href="#l6" id="l6"> 6</a> <span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></td> |
|
315 | 315 | </tr> |
|
316 | 316 | <tr class="parity0"> |
|
317 | 317 | <td class="annotate"> |
|
318 | <a href="/annotate/853dcd4de2a6/primes.py#7" | |
|
318 | <a href="/annotate/853dcd4de2a6/primes.py#l7" | |
|
319 | 319 | title="853dcd4de2a6: a">test@0</a> |
|
320 | 320 | </td> |
|
321 | 321 | <td class="source"><a href="#l7" id="l7"> 7</a> <span class="sd">"""</span></td> |
|
322 | 322 | </tr> |
|
323 | 323 | <tr class="parity1"> |
|
324 | 324 | <td class="annotate"> |
|
325 | <a href="/annotate/853dcd4de2a6/primes.py#8" | |
|
325 | <a href="/annotate/853dcd4de2a6/primes.py#l8" | |
|
326 | 326 | title="853dcd4de2a6: a">test@0</a> |
|
327 | 327 | </td> |
|
328 | 328 | <td class="source"><a href="#l8" id="l8"> 8</a> </td> |
|
329 | 329 | </tr> |
|
330 | 330 | <tr class="parity0"> |
|
331 | 331 | <td class="annotate"> |
|
332 | <a href="/annotate/853dcd4de2a6/primes.py#9" | |
|
332 | <a href="/annotate/853dcd4de2a6/primes.py#l9" | |
|
333 | 333 | title="853dcd4de2a6: a">test@0</a> |
|
334 | 334 | </td> |
|
335 | 335 | <td class="source"><a href="#l9" id="l9"> 9</a> <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span><span class="p">,</span> <span class="n">ifilter</span><span class="p">,</span> <span class="n">islice</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">chain</span></td> |
|
336 | 336 | </tr> |
|
337 | 337 | <tr class="parity1"> |
|
338 | 338 | <td class="annotate"> |
|
339 | <a href="/annotate/853dcd4de2a6/primes.py#10" | |
|
339 | <a href="/annotate/853dcd4de2a6/primes.py#l10" | |
|
340 | 340 | title="853dcd4de2a6: a">test@0</a> |
|
341 | 341 | </td> |
|
342 | 342 | <td class="source"><a href="#l10" id="l10"> 10</a> </td> |
|
343 | 343 | </tr> |
|
344 | 344 | <tr class="parity0"> |
|
345 | 345 | <td class="annotate"> |
|
346 | <a href="/annotate/853dcd4de2a6/primes.py#11" | |
|
346 | <a href="/annotate/853dcd4de2a6/primes.py#l11" | |
|
347 | 347 | title="853dcd4de2a6: a">test@0</a> |
|
348 | 348 | </td> |
|
349 | 349 | <td class="source"><a href="#l11" id="l11"> 11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></td> |
|
350 | 350 | </tr> |
|
351 | 351 | <tr class="parity1"> |
|
352 | 352 | <td class="annotate"> |
|
353 | <a href="/annotate/853dcd4de2a6/primes.py#12" | |
|
353 | <a href="/annotate/853dcd4de2a6/primes.py#l12" | |
|
354 | 354 | title="853dcd4de2a6: a">test@0</a> |
|
355 | 355 | </td> |
|
356 | 356 | <td class="source"><a href="#l12" id="l12"> 12</a> <span class="sd">"""Generate all primes."""</span></td> |
|
357 | 357 | </tr> |
|
358 | 358 | <tr class="parity0"> |
|
359 | 359 | <td class="annotate"> |
|
360 | <a href="/annotate/853dcd4de2a6/primes.py#13" | |
|
360 | <a href="/annotate/853dcd4de2a6/primes.py#l13" | |
|
361 | 361 | title="853dcd4de2a6: a">test@0</a> |
|
362 | 362 | </td> |
|
363 | 363 | <td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td> |
|
364 | 364 | </tr> |
|
365 | 365 | <tr class="parity1"> |
|
366 | 366 | <td class="annotate"> |
|
367 | <a href="/annotate/853dcd4de2a6/primes.py#14" | |
|
367 | <a href="/annotate/853dcd4de2a6/primes.py#l14" | |
|
368 | 368 | title="853dcd4de2a6: a">test@0</a> |
|
369 | 369 | </td> |
|
370 | 370 | <td class="source"><a href="#l14" id="l14"> 14</a> <span class="n">p</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">next</span><span class="p">()</span></td> |
|
371 | 371 | </tr> |
|
372 | 372 | <tr class="parity0"> |
|
373 | 373 | <td class="annotate"> |
|
374 | <a href="/annotate/853dcd4de2a6/primes.py#15" | |
|
374 | <a href="/annotate/853dcd4de2a6/primes.py#l15" | |
|
375 | 375 | title="853dcd4de2a6: a">test@0</a> |
|
376 | 376 | </td> |
|
377 | 377 | <td class="source"><a href="#l15" id="l15"> 15</a> <span class="c"># It is important to yield *here* in order to stop the</span></td> |
|
378 | 378 | </tr> |
|
379 | 379 | <tr class="parity1"> |
|
380 | 380 | <td class="annotate"> |
|
381 | <a href="/annotate/853dcd4de2a6/primes.py#16" | |
|
381 | <a href="/annotate/853dcd4de2a6/primes.py#l16" | |
|
382 | 382 | title="853dcd4de2a6: a">test@0</a> |
|
383 | 383 | </td> |
|
384 | 384 | <td class="source"><a href="#l16" id="l16"> 16</a> <span class="c"># infinite recursion.</span></td> |
|
385 | 385 | </tr> |
|
386 | 386 | <tr class="parity0"> |
|
387 | 387 | <td class="annotate"> |
|
388 | <a href="/annotate/853dcd4de2a6/primes.py#17" | |
|
388 | <a href="/annotate/853dcd4de2a6/primes.py#l17" | |
|
389 | 389 | title="853dcd4de2a6: a">test@0</a> |
|
390 | 390 | </td> |
|
391 | 391 | <td class="source"><a href="#l17" id="l17"> 17</a> <span class="kn">yield</span> <span class="n">p</span></td> |
|
392 | 392 | </tr> |
|
393 | 393 | <tr class="parity1"> |
|
394 | 394 | <td class="annotate"> |
|
395 | <a href="/annotate/853dcd4de2a6/primes.py#18" | |
|
395 | <a href="/annotate/853dcd4de2a6/primes.py#l18" | |
|
396 | 396 | title="853dcd4de2a6: a">test@0</a> |
|
397 | 397 | </td> |
|
398 | 398 | <td class="source"><a href="#l18" id="l18"> 18</a> <span class="n">ns</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">%</span> <span class="n">p</span> <span class="o">!=</span> <span class="mf">0</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span></td> |
|
399 | 399 | </tr> |
|
400 | 400 | <tr class="parity0"> |
|
401 | 401 | <td class="annotate"> |
|
402 | <a href="/annotate/853dcd4de2a6/primes.py#19" | |
|
402 | <a href="/annotate/853dcd4de2a6/primes.py#l19" | |
|
403 | 403 | title="853dcd4de2a6: a">test@0</a> |
|
404 | 404 | </td> |
|
405 | 405 | <td class="source"><a href="#l19" id="l19"> 19</a> <span class="kn">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td> |
|
406 | 406 | </tr> |
|
407 | 407 | <tr class="parity1"> |
|
408 | 408 | <td class="annotate"> |
|
409 | <a href="/annotate/853dcd4de2a6/primes.py#20" | |
|
409 | <a href="/annotate/853dcd4de2a6/primes.py#l20" | |
|
410 | 410 | title="853dcd4de2a6: a">test@0</a> |
|
411 | 411 | </td> |
|
412 | 412 | <td class="source"><a href="#l20" id="l20"> 20</a> <span class="kn">yield</span> <span class="n">n</span></td> |
|
413 | 413 | </tr> |
|
414 | 414 | <tr class="parity0"> |
|
415 | 415 | <td class="annotate"> |
|
416 | <a href="/annotate/853dcd4de2a6/primes.py#21" | |
|
416 | <a href="/annotate/853dcd4de2a6/primes.py#l21" | |
|
417 | 417 | title="853dcd4de2a6: a">test@0</a> |
|
418 | 418 | </td> |
|
419 | 419 | <td class="source"><a href="#l21" id="l21"> 21</a> </td> |
|
420 | 420 | </tr> |
|
421 | 421 | <tr class="parity1"> |
|
422 | 422 | <td class="annotate"> |
|
423 | <a href="/annotate/853dcd4de2a6/primes.py#22" | |
|
423 | <a href="/annotate/853dcd4de2a6/primes.py#l22" | |
|
424 | 424 | title="853dcd4de2a6: a">test@0</a> |
|
425 | 425 | </td> |
|
426 | 426 | <td class="source"><a href="#l22" id="l22"> 22</a> <span class="n">odds</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">%</span> <span class="mf">2</span> <span class="o">==</span> <span class="mf">1</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span></td> |
|
427 | 427 | </tr> |
|
428 | 428 | <tr class="parity0"> |
|
429 | 429 | <td class="annotate"> |
|
430 | <a href="/annotate/853dcd4de2a6/primes.py#23" | |
|
430 | <a href="/annotate/853dcd4de2a6/primes.py#l23" | |
|
431 | 431 | title="853dcd4de2a6: a">test@0</a> |
|
432 | 432 | </td> |
|
433 | 433 | <td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">return</span> <span class="n">chain</span><span class="p">([</span><span class="mf">2</span><span class="p">],</span> <span class="n">sieve</span><span class="p">(</span><span class="n">dropwhile</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o"><</span> <span class="mf">3</span><span class="p">,</span> <span class="n">odds</span><span class="p">)))</span></td> |
|
434 | 434 | </tr> |
|
435 | 435 | <tr class="parity1"> |
|
436 | 436 | <td class="annotate"> |
|
437 | <a href="/annotate/853dcd4de2a6/primes.py#24" | |
|
437 | <a href="/annotate/853dcd4de2a6/primes.py#l24" | |
|
438 | 438 | title="853dcd4de2a6: a">test@0</a> |
|
439 | 439 | </td> |
|
440 | 440 | <td class="source"><a href="#l24" id="l24"> 24</a> </td> |
|
441 | 441 | </tr> |
|
442 | 442 | <tr class="parity0"> |
|
443 | 443 | <td class="annotate"> |
|
444 | <a href="/annotate/853dcd4de2a6/primes.py#25" | |
|
444 | <a href="/annotate/853dcd4de2a6/primes.py#l25" | |
|
445 | 445 | title="853dcd4de2a6: a">test@0</a> |
|
446 | 446 | </td> |
|
447 | 447 | <td class="source"><a href="#l25" id="l25"> 25</a> <span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span></td> |
|
448 | 448 | </tr> |
|
449 | 449 | <tr class="parity1"> |
|
450 | 450 | <td class="annotate"> |
|
451 | <a href="/annotate/853dcd4de2a6/primes.py#26" | |
|
451 | <a href="/annotate/853dcd4de2a6/primes.py#l26" | |
|
452 | 452 | title="853dcd4de2a6: a">test@0</a> |
|
453 | 453 | </td> |
|
454 | 454 | <td class="source"><a href="#l26" id="l26"> 26</a> <span class="kn">import</span> <span class="nn">sys</span></td> |
|
455 | 455 | </tr> |
|
456 | 456 | <tr class="parity0"> |
|
457 | 457 | <td class="annotate"> |
|
458 | <a href="/annotate/853dcd4de2a6/primes.py#27" | |
|
458 | <a href="/annotate/853dcd4de2a6/primes.py#l27" | |
|
459 | 459 | title="853dcd4de2a6: a">test@0</a> |
|
460 | 460 | </td> |
|
461 | 461 | <td class="source"><a href="#l27" id="l27"> 27</a> <span class="kn">try</span><span class="p">:</span></td> |
|
462 | 462 | </tr> |
|
463 | 463 | <tr class="parity1"> |
|
464 | 464 | <td class="annotate"> |
|
465 | <a href="/annotate/853dcd4de2a6/primes.py#28" | |
|
465 | <a href="/annotate/853dcd4de2a6/primes.py#l28" | |
|
466 | 466 | title="853dcd4de2a6: a">test@0</a> |
|
467 | 467 | </td> |
|
468 | 468 | <td class="source"><a href="#l28" id="l28"> 28</a> <span class="n">n</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></td> |
|
469 | 469 | </tr> |
|
470 | 470 | <tr class="parity0"> |
|
471 | 471 | <td class="annotate"> |
|
472 | <a href="/annotate/853dcd4de2a6/primes.py#29" | |
|
472 | <a href="/annotate/853dcd4de2a6/primes.py#l29" | |
|
473 | 473 | title="853dcd4de2a6: a">test@0</a> |
|
474 | 474 | </td> |
|
475 | 475 | <td class="source"><a href="#l29" id="l29"> 29</a> <span class="kn">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span></td> |
|
476 | 476 | </tr> |
|
477 | 477 | <tr class="parity1"> |
|
478 | 478 | <td class="annotate"> |
|
479 | <a href="/annotate/853dcd4de2a6/primes.py#30" | |
|
479 | <a href="/annotate/853dcd4de2a6/primes.py#l30" | |
|
480 | 480 | title="853dcd4de2a6: a">test@0</a> |
|
481 | 481 | </td> |
|
482 | 482 | <td class="source"><a href="#l30" id="l30"> 30</a> <span class="n">n</span> <span class="o">=</span> <span class="mf">10</span></td> |
|
483 | 483 | </tr> |
|
484 | 484 | <tr class="parity0"> |
|
485 | 485 | <td class="annotate"> |
|
486 | <a href="/annotate/853dcd4de2a6/primes.py#31" | |
|
486 | <a href="/annotate/853dcd4de2a6/primes.py#l31" | |
|
487 | 487 | title="853dcd4de2a6: a">test@0</a> |
|
488 | 488 | </td> |
|
489 | 489 | <td class="source"><a href="#l31" id="l31"> 31</a> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></td> |
|
490 | 490 | </tr> |
|
491 | 491 | <tr class="parity1"> |
|
492 | 492 | <td class="annotate"> |
|
493 | <a href="/annotate/853dcd4de2a6/primes.py#32" | |
|
493 | <a href="/annotate/853dcd4de2a6/primes.py#l32" | |
|
494 | 494 | title="853dcd4de2a6: a">test@0</a> |
|
495 | 495 | </td> |
|
496 | 496 | <td class="source"><a href="#l32" id="l32"> 32</a> <span class="kn">print</span> <span class="s">"The first </span><span class="si">%d</span><span class="s"> primes: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">islice</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">n</span><span class="p">)))</span></td> |
General Comments 0
You need to be logged in to leave comments.
Login now