Created
June 4, 2021 07:07
-
-
Save Kernelzero/6271599d5ade0de949d608ae6f243090 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
N = int(input()) | |
result = 0 | |
array = list() | |
def calculateOdd(n): | |
if n != 1: | |
result = 3 * n + 1 | |
else: | |
result = 1 | |
return result | |
def calculateEven(m): | |
m //= 2 | |
return m | |
def calculate(k): | |
global result | |
if k != 1: | |
array.append(k) | |
if k % 2 == 0: | |
result = calculateEven(k) | |
else: | |
result = calculateOdd(k) | |
if result != 1: | |
calculate(result) | |
else: | |
array.append(result) | |
calculate(N) | |
array.insert(0, N) | |
def printArray(): | |
if len(array) > 1: | |
p = array.pop() | |
print(p) | |
printArray() | |
printArray() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment