def kaprekars_constant(n):
    """Kaprekar's constant."""
    if n == 6174:
        return 1

    n = str(n).zfill(4)
    g = ''.join(sorted(n)[::-1])
    l = ''.join(sorted(n))
    n = int(g) - int(l)

    return 1 + kaprekars_constant(n) if n != 6174 else 1