Skip to content

Instantly share code, notes, and snippets.

@Kernelzero
Created June 4, 2021 07:07
Show Gist options
  • Save Kernelzero/6271599d5ade0de949d608ae6f243090 to your computer and use it in GitHub Desktop.
Save Kernelzero/6271599d5ade0de949d608ae6f243090 to your computer and use it in GitHub Desktop.
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