示例#1
0
"""Thi is Problem 45 of ProjectEuler

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:

Triangle                Tn=n(n+1)/2             1, 3, 6, 10, 15, ...
Pentagonal              Pn=n(3n-1)/2             1, 5, 12, 22, 35, ...
Hexagonal               Hn=n(2n-1)               1, 6, 15, 28, 45, ...
It can be verified that T285 = P165 = H143 = 40755.

Find the next triangle number that is also pentagonal and hexagonal."""

__author__ = "Andrew Phoenix"

import math
import eulib

#This Method was intended to search along the line of hex numbers
#and break out when it found something that was also a tri and a
#pent. I think it's a little processor crazy.

for x in range (144,1000000):
  H=eulib.genhex(x)
  print H,
  if eulib.ispent(H)==True:
    if eulib.istri(H)==True:
      print H, 'is the answer. It is H of', x
      break

示例#2
0
"""This is Problem 44 of ProjectEuler

Pentagonal numbers are generated with this formula:

Pentagonal              Pn=n(3n-1)/2             1, 5, 12, 22, 35, ...

Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and D = |Pk  Pj| is minimised; what is the value of D?
"""
__author__ = "Andrew Phoenix"

import math
import eulib

top = 2167

for x in range(1, top):
    for y in range(x, top):
        if eulib.ispent(math.fabs(eulib.genpent(y) - eulib.genpent(x))):
            if eulib.ispent((eulib.genpent(y) + eulib.genpent(x))):
                print x, eulib.genpent(x), y, eulib.genpent(
                    y), eulib.genpent(y) - eulib.genpent(x)
                break
示例#3
0
"""Thi is Problem 45 of ProjectEuler

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:

Triangle                Tn=n(n+1)/2             1, 3, 6, 10, 15, ...
Pentagonal              Pn=n(3n-1)/2             1, 5, 12, 22, 35, ...
Hexagonal               Hn=n(2n-1)               1, 6, 15, 28, 45, ...
It can be verified that T285 = P165 = H143 = 40755.

Find the next triangle number that is also pentagonal and hexagonal."""

__author__ = "Andrew Phoenix"

import math
import eulib

#This Method was intended to search along the line of hex numbers
#and break out when it found something that was also a tri and a
#pent. I think it's a little processor crazy.

for x in range(144, 1000000):
    H = eulib.genhex(x)
    print H,
    if eulib.ispent(H) == True:
        if eulib.istri(H) == True:
            print H, 'is the answer. It is H of', x
            break