155 – Twin Primes

Today is a senior skip day so we talked Twin Prime conjecture and the new discovery. Used the Slate article and Mr. Honner’s writeup for basis. Fantastic. Also wrote up a quick python script to print twin primes. Runs pretty quick, finds the first half a million in around 10 minutes. So no picture today, but here’s some code 🙂

from math import sqrt

def prime(n):
   for i in range(2,int(sqrt(n))+1):
      if (n%i == 0):
         return False
   return True

count = 1
numberfound = 0
previous = 0
while True:
   if count % 5 != 0:
      if prime(count):
         if prime(count + 2):
            numberfound += 1
            print "number found ",
            print numberfound,
            print "twin primes",
            print count,
            print count + 2,
            print " the gap is ",
            print count - previous
            previous = count
   count = count + 2



Leave a Reply

Your email address will not be published. Required fields are marked *