Skip to content

Instantly share code, notes, and snippets.

@SirMefju
Created March 15, 2022 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirMefju/f94d683374cd3ba6250ab63d9b92eafe to your computer and use it in GitHub Desktop.
Save SirMefju/f94d683374cd3ba6250ab63d9b92eafe to your computer and use it in GitHub Desktop.
def collatz(number):
checked_number = number
table = []
while number != 1:
if number % 2 == 0:
number = number / 2
else:
number = 3 * number + 1
print(int(number))
table.append(int(number))
max_value = None
max_idx = None
for idx, num in enumerate(table):
if (max_value is None or num > max_value):
max_value = num
max_idx = idx
print('You checked number:', checked_number)
print('Maximum value:', max_value, "at place:", max_idx + 1)
print('Number of iterations:', len(table))
def main():
choice = input()
if choice.isnumeric():
number = int(choice)
collatz(number)
else:
print('Wrong choice, try again..')
main()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment