PyPE solution to PE problem 42

Registered by Scott Armitage

PyPE solution to PE problem 42

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 42
    ===========================

    The nth term of the sequence of triangle numbers is given by

        t_n = 0.5*n*(n+1)

    so the first ten triangle numbers are:

        1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

    By converting each letter in a word to a number corresponding to its
    alphabetical position and adding these values we form a word value. For
    example, the word value for SKY is 19 + 11 + 25 = 55 = t_(10). If the
    word value is a triangle number then we shall call the word a triangle
    word.

    Using words.txt (right click and 'Save Link/Target As...'), a 16K text
    file containing nearly two-thousand common English words, how many are
    triangle words?

    Solution
    --------

    There are two components to this problem -- the first is to calculate the
    word value for each entry in the file. This is relatively simple and is
    covered in word_value(...), which assumes upper-case and relative to 'A'.

    The second part of the problem is determining wheter a given number is
    triangular or not. From Wikipedia|Triangular_number:

        By analogy with the concept of square roots of x, one can define the
        triangular roots of x as:

            n = \frac{-1\pm\sqrt{8x+1}}{2}.

        An integer x is triangular exactly if 8x + 1 is a square. Equivalently,
        if the positive triangular root n of x is an integer. Then x is the nth
        triangular number.

    So basically, all we need to do is see if 8x + 1 is an integer. If so, then
    x is a triangular number.

    Answer
    ------

    162

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.