Created
March 15, 2022 14:21
-
-
Save SirMefju/f94d683374cd3ba6250ab63d9b92eafe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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