Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states:

Every even integer greater than 2 can be expressed as the sum of two primes.
For example: 

`6 = 3 + 3`
`8 = 3 + 5`
`10 = 3 + 7 = 5 + 5`
`12 = 5 + 7`

Some rules for the conjecture: 

- pairs should be descending like [3,5] not [5,3]

- all pairs should be in ascending order based on the first element of the pair: 
`[[5, 13], [7, 11]]` is accepted 
but `[[7, 11],[5, 13]]` is not accepted.

Write the a function that find all identical pairs of prime numbers:
```python
def goldbach(even_number)
```
You should return an array of containing pairs of primes, like:
```python
[[5, 13], [7, 11]]  # even_number = 18
```
or
```python
[[3, 31], [5, 29], [11, 23], [17, 17]] # even_number = 34
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def goldbach(n):
	

Solutions:
def goldbach(n):
	if n < 2:
		return []
	if n == 4:
		return [[2, 2]]
	l = n - 2
	sieve = [True] * (l // 2)
	for i in range(3, int(l ** 0.5) + 1, 2):
		if sieve[i // 2]:
			sieve[i * i // 2::i] = [False] * ((l - i * i - 1) // (2 * i) + 1)
	primes = [2 * i + 1 for i in range(1, l // 2) if sieve[i]]
	return [[p, n - p] for p in primes if n - p in primes and p <= n - p]


is_prime = lambda n: n > 1 and all((n % j for j in range(2, int(n ** 0.5) + 1)))
goldbach = lambda n: [[i, n - i] for i in range(2, int(n / 2) + 1) if is_prime(i) and is_prime(n - i)]


import numpy as np
N = 100001
s = np.ones(N)
s[:2] = 0
s[2 * 2::2] = 0
for i in range(3, int(N ** 0.5) + 1):
	if s[i]:
		s[i * i::i] = 0
primes = {i for (i, x) in enumerate(s) if x}

def goldbach(n):
	if n == 4:
		return [[2, 2]]
	return [[i, n - i] for i in range(3, n // 2 + 1, 2) if i in primes and n - i in primes]


def isprime(n):
	return n > 1 and all((n % i for i in range(2, int(n ** 0.5) + 1)))

def goldbach(n):
	return [[a, b] for (a, b) in zip(range(1, n), range(n - 1, 0, -1)) if a <= b and isprime(a) and isprime(b)]


isprime = lambda x: x > 1 and all((x % i for i in range(2, int(x ** 0.5) + 1)))
goldbach = lambda n: [[i, n - i] for i in range(n // 2 + 1) if isprime(i) and isprime(n - i)]


def era(n):
	l = [True for i in range(0, n + 1)]
	l[0] = l[1] = False
	for i in range(2, n + 1):
		if l[i]:
			for j in range(i * i, n + 1, i):
				l[j] = False
	for (i, _) in enumerate(l):
		if _:
			yield i

def goldbach(n):
	res = []
	p = list(era(n))
	for x in p:
		if n - x in p:
			if n - x < x:
				return res
			res.append([x, n - x])
	return res


import math

def goldbach(en):
	r = []
	for j in range(2, int(en / 2) + 1):
		if isPrime(j) and isPrime(en - j):
			r.append([j, en - j])
	return r

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