Skip to content

Instantly share code, notes, and snippets.

@Mjiig
Created July 30, 2012 21:35
Show Gist options
  • Save Mjiig/3210463 to your computer and use it in GitHub Desktop.
Save Mjiig/3210463 to your computer and use it in GitHub Desktop.
class Pentagonals(object):
def __init__(self):
self._nums={}
def add_pent(self):
n=len(self._nums)+1
self._nums[n-1]=(n*((3*n)-1)/2)
def is_pent(self, n):
return n in self._nums
def __getitem__(self, n): #special function accessible via []
while n>=len(self._nums):
self.add_pent()
return self._nums[n-1]
a = 2
finished=False
pents=Pentagonals()
while not finished:
for b in range(1, a):
a_pent, b_pent = pents[a], pents[b]
if pents.is_pent(a_pent-b_pent) and pents.is_pent(a_pent+b_pent):
print
print a_pent-b_pent
finished=True
a+=1
print str(a) + "\r",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment