User:Yeti: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 9: Line 9:
</pre>
</pre>


=Primes=
=Primes/Python/FSOE==
==Python==
{{works with|Python|2.x}}
{{works with|Python|2.x}}
This is a sequentialised variant of the well known sieve method (ab)using a dictionary as sparse array.
This is a sequentialised variant of the well known sieve method (ab)using a dictionary as sparse array.
Line 20: Line 19:
if n in L:
if n in L:
P = L[n]
P = L[n]
del L[n] # optional - just saves some memory.
del L[n] # optional - saves some memory.
else:
else:
print n
print n

Revision as of 19:52, 24 February 2019

My Sandbox

I need to get used to this flavour of markup first. That'll take some time. Meanwhile I collect my examples here. If you think, some example is worth being moved to the "right" place, feel free to do so and leave me a note...


Arithmetic/Complex#Dc

in incubator at http://yeti.freeshell.org/orgy/dc/dc.html#:rosetta-code:arithmetic:complex

Primes/Python/FSOE=

Works with: Python version 2.x

This is a sequentialised variant of the well known sieve method (ab)using a dictionary as sparse array. <lang python>L = {} n = 2

while 1:

       if n in L:
               P = L[n]
               del L[n] # optional - 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>
Output:
2
3
5
7
11
13
17
19
23
29

...the program has to be terminated by the user e.g. by typing ctrl-c.


My Favorite Languages
Language Proficiency
AWK ---
C ---
Dc ---
Spin ---