PyPE solution to PE problem 45

Registered by Scott Armitage

PyPE solution to PE problem 45

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Scott Armitage
Completed by
Scott Armitage

Related branches

Sprints

Whiteboard

    ProjectEuler.net problem 45
    ===========================

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

        Triangle T_(n)=n(n+1)/2 1, 3, 6, 10, 15, ...
        Pentagonal P_(n)=n(3n-1)/2 1, 5, 12, 22, 35, ...
        Hexagonal H_(n)=n(2n-1) 1, 6, 15, 28, 45, ...

    It can be verified that T_(285) = P_(165) = H_(143) = 40755.

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

    Solution
    --------

    We have a starting point (H_143), and we have a formula for generating
    triangular, pentagonal, and hexagonal nubmers. Since the formula for
    hexagonal numbers generates the shortest list, we start counting from
    here and calculate each subsequent H_n.

    Note that all hexagonal numbers are also triangular numbers, and so we
    only need to check if each resulting H_n is also pentagonal. If it is,
    we return H_n as our answer; otherwise, we keep going.

    The test in ispentagonal is derived from the P(n) function above, solving
    for the roots n for a given x. If the roots n are integer, then x is P_n.

    Answer
    ------

    1533776805

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.