def desc_digit(num):
    num_str = str(num)
    while not len(num_str) == 4:
        num_str = '0' + num_str
    num_list = list(num_str)
    output = ''
    while len(num_list) > 0:
        output += max(num_list)
        num_list.remove(max(num_list))
    return int(output)


def largest_digit(num):
    num_str = str(num)
    return int(max(list(num_str)))


def asc_digit(num):
    num_str = str(num)
    while not len(num_str) == 4:
        num_str += '0'
    num_list = list(num_str)
    output = ''
    while len(num_list) > 0:
        output += min(num_list)
        num_list.remove(min(num_list))
    return int(output)


def kaprekar(num):
    assert len(str(num)) < 5, 'Please enter a number 4 digits or lower.'
    output = str(num) + ' -> '
    count = 0
    while not num == 6174:
        num = desc_digit(num) - asc_digit(num)
        count += 1
    return print(output + str(count))


input = [6589, 5455, 6174]
for i in input:
    kaprekar(i)