Problem 27

completed December 6, 2011

Comments

It’s need that in a list of lists, the max() operator can still work. It pulls the item with the largest value of it’s first object. This problem was pretty fun and just because there were so many little steps in it. This is also the first problem that used negative numbers.

Code

def isprime(n):
	for i in range(2, int(n**0.5 + 1)):
		if n%i == 0: return 'FALSE'
	return 'TRUE'

from itertools import count
def longest(a, b):
	for n in count(0):
		quadratic = n**2 + a*n + b 
		if quadratic < 0: return 0
		elif isprime(quadratic) == 'FALSE': return n
		
this = []
for a in range(-1000, 1000):
	for b in range(-1000, 1000):
		print a, b
		this.append([longest(a, b), a*b])
	
print max(this)