Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Sieve of Eratosthenes

Name: Anonymous 2013-11-05 16:22

Do you guys like my sieve of eratosthenes?

https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes


print "2\n3\n5\n7"
for a in range(2, 121):
    if a % 2 != 0:
        if a % 3 != 0:
            if a % 5 != 0:
                if a % 7 != 0:
                    print a

Name: Anonymous 2013-11-05 17:32

I like it because it is witty and ironic because it doesn't work for numbers larger than 49 and it prints the first four primes twice.

Name: Anonymous 2013-11-05 18:39

=) why wouldn't it work for numbers over 49?

Name: Anonymous 2013-11-05 18:41

it stops working above 120

Name: Anonymous 2013-11-05 19:03

>>2
>le pedophile sage

Name: Anonymous 2013-11-05 23:12

I wrote this a few years ago. This one actually works.

#! /usr/local/bin/python

import math

def sieve(limit):
    param = int(math.ceil(math.sqrt(limit)))
    primes = []
    for i in range(2,param):
        state = True
        for j in range(2,i):
            if i==j:
                continue
            elif i%j==0:
                state = False
                break
        if state:
            primes.append(i)
    end = len(primes) - 1
    go = primes[end] + 1
    for i in range(go,limit):
        state = True
        for key, prime in enumerate(primes):
            if i == prime:
                continue
            elif i % prime == 0:
                state = False
                break
        if state:
            primes.append(i)
    print primes

sieve(100000)

Replace "100000" with whatever limit you want to cap it at.

Name: Anonymous 2013-11-06 1:25

>le pedophile forced indentation

Name: Anonymous 2013-11-06 2:04

A boy died in 1932 by a homicidal murderer. He buried him in the ground when he was still alive. The murdered chanted, "Toma sota balcu" as he buried him. Now that you have read the chant, you will meet this little boy. In the middle of the night he will be on your ceiling. He will suffocate you like he was suffocated. If you post this, he will not bother you. Your kindness will be rewarded.

Name: Anonymous 2013-11-06 16:03

>>2
It doesn't print the first four primes twice nerd.

also works for numbers larger than 49.

Don't change these.
Name: Email:
Entire Thread Thread List