Advertisement
here2share

# collatz_conjecture.py

Dec 27th, 2022
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # collatz_conjecture.py
  2.  
  3. # finally solved by chatgpt?
  4.  
  5. def collatz_conjecture(n):
  6.     result = []
  7.     def cc(n):
  8.         if n == 1:
  9.             return
  10.         elif n % 2 == 0:
  11.             v = n // 2
  12.             result.append(v)
  13.             cc(v)
  14.         else:
  15.             v = 3 * n + 1
  16.             result.append(v)
  17.             cc(v)
  18.     cc(n)
  19.     print(result)
  20.  
  21. collatz_conjecture(10)
  22.  
  23. collatz_conjecture(15)
  24.  
  25. collatz_conjecture(99)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement