"""
Problem 12: What is the value of the first triangle number to have over five hundred divisors?
"""

from . import helpers


def triangle_numbers():
    """
    An unlimited generator of triangle numbers.
    The nth triangle number is generated by adding the first n natural numbers.

    Usage:

    >>> gen = triangle_numbers()
    >>> next(gen)
    1
    >>> next(gen)
    3
    >>> next(gen)
    6
    >>> next(gen)
    10
    """

    current = 0
    i = 1

    while True:
        current += i
        i += 1
        yield current


def solve():
    gen = triangle_numbers()
    while True:
        current = next(gen)
        if len(helpers.factors(current)) > 500:
            return current
