Browsed by
Month: June 2015

Sieve Of Eratosthenes (Still on Prime)

Sieve Of Eratosthenes (Still on Prime)

I could not make my code any better so I decided that I new approach needed to be found… Boom Eratosthenes came to the rescue. I found those two great web sites: Sieve Of Eratosthenes explained and Sieve Of Eratosthenes code. In the second link I found a bit of code that run 10^7 in few seconds, with my old code to get a 10^8 with multi treading took few days! Shocked is the word I will used! Below is…

Read More Read More

Multi Threading and still looking for Primes

Multi Threading and still looking for Primes

Added some Multi Threading to my code to get full advantage of the dual core on my laptop: import threading import time import inspect import sqlite3 import math class Thread(threading.Thread): def __init__(self, t, *args): threading.Thread.__init__(self, target=t, args=args) self.start() # global variables count = 0 lock = threading.Lock() primeList = [] dbname=’/home/roberto/primelist.db’ table_name = ‘primes’ # name of the table to be created new_field = ‘prime’ # name of the column field_type = ‘INTEGER’ # column data type def createDB(): #…

Read More Read More

Prime number 2. The sqlite strikes back!

Prime number 2. The sqlite strikes back!

Finally got some code working with saving the Primes on a DB. I started by saving as I find the prime and realised that the constant IO activity was slowing the all process down. Next step was multi treading: this is still not 100%. Here is the code so far: # Python program to calculate prime numbers import math import threading import sqlite3 count = 0 primeList = [] dbname=’/home/roberto/primelist.db’ table_name = ‘primes’ # name of the table to be…

Read More Read More

How to find BIG prime numbers

How to find BIG prime numbers

If my calculations are right the best way to find a BIG prime number is to iterate through all the prime numbers before it, why? Because the quickest way to check a prime is to see if it is divisible by all the previous primes, I am not going to waste any processing power on non prime can be defined with prime numbers like 63 = 7*3^2. So here is my first attempt to find that BIG prime. (With BIG…

Read More Read More