Initial commit

This commit is contained in:
Kevin Keogh
2018-07-02 15:45:49 -04:00
parent 60b3954a3b
commit fd817f8811
28 changed files with 809 additions and 0 deletions

37
problem-27.py Normal file
View File

@@ -0,0 +1,37 @@
import math
import itertools
def is_prime(n):
if n % 2 == 0 and n > 2 or n < 0:
return False
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
def form(n, a, b):
result = n**2 + a*n + b
return n**2 + a*n + b
def get_sequence(pair):
i = 0
while True:
if not is_prime(form(i, pair[0], pair[1])):
return list(range(i))
i += 1
if __name__ == '__main__':
a = list(range(-1000, 1000))
b = list(range(-1000, 1001))
pairs = list(itertools.product(a, b))
print('number of pairs:', len(pairs))
longest = [pairs[0], [0]]
for pair in pairs:
seq = get_sequence(pair)
if len(seq) > len(longest[1]):
longest = (pair, seq)
print(longest)