User:Yeti: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 28: | Line 28: | ||
Is there really no simpler way to drop the top of stack that works for strings and numbers and in all versions of Dc? |
Is there really no simpler way to drop the top of stack that works for strings and numbers and in all versions of Dc? |
||
=Python/Primes/ |
=Python/Primes/FSOE= |
||
{{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 34: | Line 34: | ||
Alternatively you can describe it as finding the wheels and moving them on a tape. The only knowledge is to start looking 2 instead of starting with 1, but the original sieve does skip 1 too. 2 is not hard coded to be prime. The algorithm detects it as 1st prime and then puts the 2-wheel on the tape. |
Alternatively you can describe it as finding the wheels and moving them on a tape. The only knowledge is to start looking 2 instead of starting with 1, but the original sieve does skip 1 too. 2 is not hard coded to be prime. The algorithm detects it as 1st prime and then puts the 2-wheel on the tape. |
||
==Python/Primes/FSOE1== |
|||
⚫ | |||
⚫ | |||
<lang python>L = {} |
<lang python>L = {} |
||
Line 72: | Line 74: | ||
...the program has to be terminated by the user e.g. by typing ctrl-c. |
...the program has to be terminated by the user e.g. by typing ctrl-c. |
||
=Python/Primes/FSOE3= |
==Python/Primes/FSOE3== |
||
{{works with|Python|2.x}} |
{{works with|Python|2.x}} |
||
⚫ | |||
Variant: A tape position can hold one wheel. |
|||
L = {} |
|||
⚫ | |||
n = 2 |
n = 2 |
||
Line 82: | Line 86: | ||
if n in L: |
if n in L: |
||
P = L[n] |
P = L[n] |
||
del L[n] # optional - saves some memory. |
|||
else: |
else: |
||
P = n |
P = n |