I couldn't resist!
import pandas as pd primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] data = [] for i in range(len(primes)): for j in range(i+1,len(primes)): x = primes[i] y = primes[j] z = x + y data.append({'z':z,'x':x,'y':y}) data = pd.DataFrame.from_dict(data) counts = data.groupby('z').agg(count=('z','count')) counts.loc[counts['count']==2]
The answer (conditional on being less than 100) is 68. But there are more that are greater than 100.
68 = 7 + 61 68 = 31 + 37
68 is correct.
Are you sure about the ones larger than 100 though? Maybe you need to add all the primes up to that supposed candidate number in your primes list to make sure they don't end up breaking that "exactly two" constraint.
reply
Ah, you're right about larger than 100. I can't find one larger than 68. Revised script:
import pandas as pd def get_primes(n): out = list() sieve = [True] * (n+1) for p in range(2, n+1): if (sieve[p]): out.append(p) for i in range(p, n+1, p): sieve[i] = False return out n = 100 primes = get_primes(n) data = [] for i in range(len(primes)): for j in range(i+1,len(primes)): x = primes[i] y = primes[j] z = x + y if z<=n: data.append({'z':z,'x':x,'y':y}) data = pd.DataFrame.from_dict(data) counts = data.groupby('z').agg(count=('z','count')).reset_index() counts.loc[counts['count']==2].sort_values(by='z',ascending=False).head(1)
I tried up to n=10,000 and nothing higher than 68 was found.
reply
def get_primes(n): out = list() sieve = [True] * (n+1) for p in range(2, n+1): if (sieve[p]): out.append(p) for i in range(p, n+1, p): sieve[i] = False return out
Fancy pancy there with your Sieve of Eratosthenes ;)
reply
Smaller than 100 I wouldn't even have bothered with pandas lol. Good habit tho. The kind of script that I would have chatGPTed lol
reply
I’m just so used to pandas that it’s the first method I thought of
reply