
    Design a fraud detection function that examines transaction reference numbers to identify suspicious patterns by verifying if each digit appears fewer times than its actual value. For example, in a transaction ID, the digit '4' should not appear more than 4 times, and '2' should not appear more than 2 times, as excessive repetition of digits may indicate potential fraudulent activity.
    

    
def validate(n):
    """
    Design a fraud detection function that examines transaction reference numbers to identify suspicious patterns by verifying if each digit appears fewer times than its actual value. For example, in a transaction ID, the digit '4' should not appear more than 4 times, and '2' should not appear more than 2 times, as excessive repetition of digits may indicate potential fraudulent activity.
    

    """
def validate(n):
    """
    Design a fraud detection function that examines transaction reference numbers to identify suspicious patterns by verifying if each digit appears fewer times than its actual value. For example, in a transaction ID, the digit '4' should not appear more than 4 times, and '2' should not appear more than 2 times, as excessive repetition of digits may indicate potential fraudulent activity.
    

    """
    for i in range(10):
        temp = n
        count = 0
        while temp:
            if temp % 10 == i:
                count += 1
            if count > i:
                return False
            temp //= 10
    return True