User:Yeti: Difference between revisions
Content added Content deleted
m (minor edit... mwhuaahaahahahahaaa...) |
|||
Line 144: | Line 144: | ||
!!!!!!!!!!!!!!!""""""""""""#####################################"""""""""""""""" |
!!!!!!!!!!!!!!!""""""""""""#####################################"""""""""""""""" |
||
</pre> |
</pre> |
||
---- |
|||
=Primes= |
|||
=={{header|Python}}== |
|||
{{works with|Python|2.x}} |
|||
<lang python>L = {} |
|||
n = 2 |
|||
while 1: |
|||
if n in L: |
|||
P = L[n] |
|||
del L[n] # optional - just saves some memory. |
|||
else: |
|||
print n |
|||
P = [n] |
|||
for p in P: |
|||
npp = n+p |
|||
if npp in L: |
|||
L[npp].add(p) |
|||
else: |
|||
L[npp] = set([p]) |
|||
n += 1</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 |
|||
3 |
|||
5 |
|||
7 |
|||
11 |
|||
13 |
|||
17 |
|||
19 |
|||
23 |
|||
29 |
|||
</pre> |
|||
...the program has to be terminated by the user e.g. by typing ctrl-c. |
|||
---- |
---- |