history = [] while True: next = ''.join(sorted(hex(int(number, 16)-int(number[::-1], 16))[2:])[::-1]) # Generate the next number. try: if next == history[-1]: print(f'CONSTANT, {hex(next)[2:]}') break except IndexError: pass if next in history: print(f'CYCLE, {len(history)-history.index(next)}') break if next == 0: print(f'ZERO, {len(history)}') break number = next history.append(number)
adc
number = ''.join(sorted(input())[::-1])
history = [] while True: next = ''.join(sorted(hex(int(number, 16)-int(number[::-1], 16))[2:])[::-1]) # Generate the next number. try: if next == history[-1]: print(f'CONSTANT, {hex(next)[2:]}') break except IndexError: pass if next in history: print(f'CYCLE, {len(history)-history.index(next)}') break if next == 0: print(f'ZERO, {len(history)}') break number = next history.append(number)