2018-10-28 13:36:39 -08:00
|
|
|
def main():
|
|
|
|
def n31(a):# a = initial number
|
|
|
|
c = 0
|
|
|
|
l = [a]
|
|
|
|
while a != 1:
|
|
|
|
if a % 2 == 0:#if even divide it by 2
|
|
|
|
a = a // 2
|
|
|
|
elif a % 2 == 1:#if odd 3n+1
|
|
|
|
a = 3*a +1
|
|
|
|
c += 1#counter
|
|
|
|
l += [a]
|
2018-11-03 12:08:13 -08:00
|
|
|
|
2018-10-28 13:36:39 -08:00
|
|
|
return l , c
|
|
|
|
print(n31(43))
|
2018-11-03 12:08:13 -08:00
|
|
|
print(n31(98)[0][-1])# = a
|
2018-11-04 15:54:17 +01:00
|
|
|
print("It took {0} steps.".format(n31(13)[1]))#optional finish
|
2018-11-03 12:08:13 -08:00
|
|
|
|
2018-10-28 13:36:39 -08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|