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