#!/usr/bin/env python
# coding=utf-8

"""
Problem Definition :

Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2. The first ten pentagonal numbers are:

1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 - 22 = 48, is not pentagonal.

Find the pair of pentagonal numbers Pj and Pk for which their sum and difference are pentagonal and D = Pk − Pj is minimised what is the value of D?

"""

__author__ = 'vivek'

import time
import math

def pentagonal(n):
    return n*(3*n - 1)/2


def main():

    start_time = time.clock()
    limit = 5000
    penta_numbers = [pentagonal(x) for x in range(1, limit)]
    found = 0
    for i in range(0, limit-1):
        for j in xrange(0, i):
            number1 = penta_numbers[i]
            number2 = penta_numbers[j]
            if number1 - number2 in penta_numbers:# and number2-number1 in penta_numbers:
                if number1 + number2 in penta_numbers:
                    print(number1, number2, number1-number2)
                    found = 1
                    break
        if found:
            break
    print("Run time...{} secs \n".format(round(time.clock() - start_time, 4)))

if __name__ == "__main__":
    main()

26e4b064f818a103dc3949a49ceb46c2a2bbfbba
<mask token>


def pentagonal(n):
    return n * (3 * n - 1) / 2


def main():
    start_time = time.clock()
    limit = 5000
    penta_numbers = [pentagonal(x) for x in range(1, limit)]
    found = 0
    for i in range(0, limit - 1):
        for j in xrange(0, i):
            number1 = penta_numbers[i]
            number2 = penta_numbers[j]
            if number1 - number2 in penta_numbers:
                if number1 + number2 in penta_numbers:
                    print(number1, number2, number1 - number2)
                    found = 1
                    break
        if found:
            break
    print('Run time...{} secs \n'.format(round(time.clock() - start_time, 4)))


<mask token>

<mask token>


def pentagonal(n):
    return n * (3 * n - 1) / 2


def main():
    start_time = time.clock()
    limit = 5000
    penta_numbers = [pentagonal(x) for x in range(1, limit)]
    found = 0
    for i in range(0, limit - 1):
        for j in xrange(0, i):
            number1 = penta_numbers[i]
            number2 = penta_numbers[j]
            if number1 - number2 in penta_numbers:
                if number1 + number2 in penta_numbers:
                    print(number1, number2, number1 - number2)
                    found = 1
                    break
        if found:
            break
    print('Run time...{} secs \n'.format(round(time.clock() - start_time, 4)))


if __name__ == '__main__':
    main()

<mask token>
__author__ = 'vivek'
<mask token>


def pentagonal(n):
    return n * (3 * n - 1) / 2


def main():
    start_time = time.clock()
    limit = 5000
    penta_numbers = [pentagonal(x) for x in range(1, limit)]
    found = 0
    for i in range(0, limit - 1):
        for j in xrange(0, i):
            number1 = penta_numbers[i]
            number2 = penta_numbers[j]
            if number1 - number2 in penta_numbers:
                if number1 + number2 in penta_numbers:
                    print(number1, number2, number1 - number2)
                    found = 1
                    break
        if found:
            break
    print('Run time...{} secs \n'.format(round(time.clock() - start_time, 4)))


if __name__ == '__main__':
    main()

<mask token>
__author__ = 'vivek'
import time
import math


def pentagonal(n):
    return n * (3 * n - 1) / 2


def main():
    start_time = time.clock()
    limit = 5000
    penta_numbers = [pentagonal(x) for x in range(1, limit)]
    found = 0
    for i in range(0, limit - 1):
        for j in xrange(0, i):
            number1 = penta_numbers[i]
            number2 = penta_numbers[j]
            if number1 - number2 in penta_numbers:
                if number1 + number2 in penta_numbers:
                    print(number1, number2, number1 - number2)
                    found = 1
                    break
        if found:
            break
    print('Run time...{} secs \n'.format(round(time.clock() - start_time, 4)))


if __name__ == '__main__':
    main()

#!/usr/bin/env python
# coding=utf-8

"""
Problem Definition :

Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2. The first ten pentagonal numbers are:

1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 - 22 = 48, is not pentagonal.

Find the pair of pentagonal numbers Pj and Pk for which their sum and difference are pentagonal and D = Pk − Pj is minimised what is the value of D?

"""

__author__ = 'vivek'

import time
import math

def pentagonal(n):
    return n*(3*n - 1)/2


def main():

    start_time = time.clock()
    limit = 5000
    penta_numbers = [pentagonal(x) for x in range(1, limit)]
    found = 0
    for i in range(0, limit-1):
        for j in xrange(0, i):
            number1 = penta_numbers[i]
            number2 = penta_numbers[j]
            if number1 - number2 in penta_numbers:# and number2-number1 in penta_numbers:
                if number1 + number2 in penta_numbers:
                    print(number1, number2, number1-number2)
                    found = 1
                    break
        if found:
            break
    print("Run time...{} secs \n".format(round(time.clock() - start_time, 4)))

if __name__ == "__main__":
    main()
