brewersfan1976

ch2-ex14.py

Jul 7th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. # find the 2 prime numbers to equal
  2. # the even number to prove Goldbach's conjecture
  3. # Goldbach's conjecture states if you add two different prime numbers
  4. # together it will be equal to an even number
  5. # for this program we will only print out even numbers between 4 and 98
  6.  
  7. def divisors(num):
  8.     count = 1
  9.     div = 2
  10.  
  11.     while (div < num):
  12.           if (num % div == 0):
  13.              count = count + 1
  14.          
  15.           div = div + 1
  16.     return count
  17.  
  18. x = 1
  19. prime_numbers_one = []
  20. prime_numbers_two = []
  21.  
  22. while (x <= 100):
  23.       result = divisors(x)
  24.  
  25.       if (result == 1 and x != 1):
  26.          prime_numbers_one = prime_numbers_one + [x]
  27.          prime_numbers_two = prime_numbers_two + [x]
  28.  
  29.       x = x + 1
  30.  
  31. z = 4
  32. x = 0
  33. y = 0
  34.  
  35. should_restart = True
  36.  
  37. while should_restart:
  38.     should_restart = False
  39.     for x, y in [(x, y) for x in prime_numbers_one for y in prime_numbers_two]:
  40.         if (x + y == z):
  41.            print "prime number", x, "plus prime number", y, "equals", z
  42.            z = z + 2
  43.  
  44.            if (z > 98):
  45.               quit()
  46.  
  47.            should_restart = True
  48.            break
Advertisement
Add Comment
Please, Sign In to add comment