
# differs.py
# Andrew Davison, ad@coe.psu.ac.th, Nov. 2024
# David Wells - "Prime Numbers": cousin primes, sexy primes, twin primes
# https://mathworld.wolfram.com/TwinPrimeConjecture.html
# input:  2   or  4  or 6
'''
The Twin Primes Conjecture states that there are infinitely 
many twin primes, where twin primes are pairs of primes p 
and p+2 (e.g., (3, 5), (11, 13), etc.).

Cousin primes are pairs differing by 4, and sexy primes 
differ by 6
'''

import pUtils
import matplotlib.pyplot as plt


def primeDiffs(d, limit):
  diffs = []
  for p in range(2, limit):
    if pUtils.isPrime(p) and pUtils.isPrime(p + d):
      diffs.append((p, p + d))
  return diffs


limit = 1000
d = int(input("Difference? "))
diffs = primeDiffs(d, limit)

print(f"Number of pairs differing by {d} and less than {limit}: {len(diffs)}")
print(diffs)

xs, ys = zip(*diffs)
plt.scatter(xs, ys)
plt.title(f"Distribution of {d}-pair primes up to {limit}")
plt.xlabel('Prime p')
plt.ylabel(f'Pair Prime p + {d}')
plt.show()
