コード例 #1
0
def main():
    
    start = time()
    
    solutionList = []
    
    pentagonalList = [number for number in generatePentagonalNumbers(LIMIT)]
    pentagonalSet = set(pentagonalList)     # for speed
    
    i = 0
    while len(solutionList) == 0:
        for j in xrange(i, len(pentagonalList)):
            if pentagonalList[i] + pentagonalList[j] in pentagonalSet and \
            abs(pentagonalList[i] - pentagonalList[j]) in pentagonalSet:
                solutionList.append(pentagonalList[i])
                solutionList.append(pentagonalList[j])
        i += 1
    
    
    print "Solutions: ", solutionList
    print "|Difference|: ", abs(solutionList[1] - solutionList[0])
            
    end = time()
    
    print "Runtime: ", end - start, " seconds."
コード例 #2
0
def main():

    start = time()
    solution = -1
    setToCheck = set([number for number in generateTriangleNumbers(LIMIT, STARTING_TRIANGLE_NUMBER)]) \
        & set([number for number in generateHexagonalNumbers(LIMIT, STARTING_HEXAGONAL_NUMBER)])

    for number in generatePentagonalNumbers(LIMIT, STARTING_PENTAGONAL_NUMBER):
        if number in setToCheck:
            solution = number
            break

    print "Next Number: ", solution

    end = time()
    print "Runtime: ", end - start, " seconds. "
コード例 #3
0
def main():
    
    start = time()
    solution = -1
    setToCheck = set([number for number in generateTriangleNumbers(LIMIT, STARTING_TRIANGLE_NUMBER)]) \
        & set([number for number in generateHexagonalNumbers(LIMIT, STARTING_HEXAGONAL_NUMBER)])
    
    for number in generatePentagonalNumbers(LIMIT, STARTING_PENTAGONAL_NUMBER):
        if number in setToCheck:
            solution = number
            break
    
    print "Next Number: ", solution
            
    end = time()
    print "Runtime: ", end - start, " seconds. "
コード例 #4
0
def main():

    start = time()

    solutionList = []

    pentagonalList = [number for number in generatePentagonalNumbers(LIMIT)]
    pentagonalSet = set(pentagonalList)  # for speed

    i = 0
    while len(solutionList) == 0:
        for j in xrange(i, len(pentagonalList)):
            if pentagonalList[i] + pentagonalList[j] in pentagonalSet and \
            abs(pentagonalList[i] - pentagonalList[j]) in pentagonalSet:
                solutionList.append(pentagonalList[i])
                solutionList.append(pentagonalList[j])
        i += 1

    print "Solutions: ", solutionList
    print "|Difference|: ", abs(solutionList[1] - solutionList[0])

    end = time()

    print "Runtime: ", end - start, " seconds."