#!/usr/bin/env python3.8
# -*- coding: utf-8 -*-
"""
https://projecteuler.net/problem=45
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.
Answer: 1533776805
"""


def solution(n: int = 285) -> int:
    while n := n + 1:
        triangular_number = n * (n + 1) // 2  # triangular number
        if ((1 + 24 * triangular_number) ** 0.5) % 6 == 5.0:  # is pentagonal number
            if ((1 + 8 * triangular_number) ** 0.5) % 4 == 3.0:  # is hexagonal number
                return triangular_number


if __name__ == '__main__':
    from .evaluate import Watchdog

    with Watchdog() as wd:
        results = wd.evaluate(solution)(285, answer=1533776805)

33312a848dfc5556f6863c6cb8d9d4312627f431
<mask token>

<mask token>


def solution(n: int=285) ->int:
    while (n := n + 1):
        triangular_number = n * (n + 1) // 2
        if (1 + 24 * triangular_number) ** 0.5 % 6 == 5.0:
            if (1 + 8 * triangular_number) ** 0.5 % 4 == 3.0:
                return triangular_number


<mask token>

<mask token>


def solution(n: int=285) ->int:
    while (n := n + 1):
        triangular_number = n * (n + 1) // 2
        if (1 + 24 * triangular_number) ** 0.5 % 6 == 5.0:
            if (1 + 8 * triangular_number) ** 0.5 % 4 == 3.0:
                return triangular_number


if __name__ == '__main__':
    from .evaluate import Watchdog
    with Watchdog() as wd:
        results = wd.evaluate(solution)(285, answer=1533776805)

#!/usr/bin/env python3.8
# -*- coding: utf-8 -*-
"""
https://projecteuler.net/problem=45
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.
Answer: 1533776805
"""


def solution(n: int = 285) -> int:
    while n := n + 1:
        triangular_number = n * (n + 1) // 2  # triangular number
        if ((1 + 24 * triangular_number) ** 0.5) % 6 == 5.0:  # is pentagonal number
            if ((1 + 8 * triangular_number) ** 0.5) % 4 == 3.0:  # is hexagonal number
                return triangular_number


if __name__ == '__main__':
    from .evaluate import Watchdog

    with Watchdog() as wd:
        results = wd.evaluate(solution)(285, answer=1533776805)
