def spigot_pi():
    """Generates digits of pi using the spigot algorithm."""
    q, r, t, k, n, ll = 1, 0, 1, 1, 3, 3
    while True:
        if 4 * q + r - t < n * t:
            yield n
            q, r, t, k, n, ll = 10 * q, 10 * (r - n * t), t, k, 10 * (3 * q + r
                ) // t - 10 * n, ll
        else:
            q, r, t, k, n, ll = q * k, (2 * q + r) * ll, t * ll, k + 1, (q *
                (7 * k + 2) + r * ll) // (t * ll), ll + 2
