# Collection of code snippets by Arne Vajhøj 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
def twoxtwo(n1, n2, n3):
    return (n1 == n2 or n1 == n3 or n2 == n3)

def threexone(n1, n2, n3):
    n = [n1/10, n1%10, n2/10, n2%10, n3/10, n3%10]
    for i in range(0,10):
        if n.count(i) >= 3:
            return True
    return False

def inorder(n1, n2, n3):
    if (n1 + 1) == n2 and (n2 + 1) == n3:
        return True
    if (n1 - 1) == n2 and (n2 - 1) == n3:
        return True
    return False

total = 0
special1 = 0
special2 = 0
special3 = 0
special = 0
for n1 in range(0,100):
    for n2 in range(0,100):
        for n3 in range(0,100):
            total = total + 1
            if twoxtwo(n1, n2, n3):
                special1 = special1 + 1
                special = special + 1
            if threexone(n1, n2, n3):
                special2 = special2 + 1
                special = special + 1
            if inorder(n1, n2, n3):
                special3 = special3 + 1
                special = special + 1
print "%d out of %d has 2 identical two digits (%.2f %%)" % (special1, total, 100.0*special1/total)
print "%d out of %d has 3 identical digits (%.2f %%)" % (special2, total, 100.0*special2/total)
print "%d out of %d is order or in reverse order (%.2f %%)" % (special3, total, 100.0*special3/total)
print "%d out of %d is special (%.2f %%)" % (special, total, 100.0*special/total)
