MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / n31

Function n31

Maths/3n+1.py:2–13  ·  view source on GitHub ↗
(a)

Source from the content-addressed store, hash-verified

1def main():
2 def n31(a):# a = initial number
3 c = 0
4 l = [a]
5 while a != 1:
6 if a % 2 == 0:#if even divide it by 2
7 a = a // 2
8 elif a % 2 == 1:#if odd 3n+1
9 a = 3*a +1
10 c += 1#counter
11 l += [a]
12
13 return l , c
14 print(n31(43))
15 print(n31(98)[0][-1])# = a
16 print("It took {0} steps.".format(n31(13)[1]))#optional finish

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected