project_euler.problem_045.sol1 ============================== .. py:module:: project_euler.problem_045.sol1 .. autoapi-nested-parse:: Problem 45: https://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 * (3 * n - 1)) / 2 1, 5, 12, 22, 35, ... Hexagonal H(n) = n * (2 * n - 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. All triangle numbers are hexagonal numbers. T(2n-1) = n * (2 * n - 1) = H(n) So we shall check only for hexagonal numbers which are also pentagonal. Functions --------- .. autoapisummary:: project_euler.problem_045.sol1.hexagonal_num project_euler.problem_045.sol1.is_pentagonal project_euler.problem_045.sol1.solution Module Contents --------------- .. py:function:: hexagonal_num(n: int) -> int Returns nth hexagonal number >>> hexagonal_num(143) 40755 >>> hexagonal_num(21) 861 >>> hexagonal_num(10) 190 .. py:function:: is_pentagonal(n: int) -> bool Returns True if n is pentagonal, False otherwise. >>> is_pentagonal(330) True >>> is_pentagonal(7683) False >>> is_pentagonal(2380) True .. py:function:: solution(start: int = 144) -> int Returns the next number which is triangular, pentagonal and hexagonal. >>> solution(144) 1533776805