We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 48f2a9e commit 93742b7Copy full SHA for 93742b7
collatz_sequence.py
@@ -0,0 +1,18 @@
1
+# The Collatz Conjecture is a famous math problem.
2
+# The conjecture is that after applying a sequence of one of two transformations,
3
+# every positive integer will eventually transform into 1.
4
+# The transformations are: divide by 2 if the number is even, multiply by 3 and add 1 if its odd.
5
+# You can see more about it here https://en.wikipedia.org/wiki/Collatz_conjecture
6
+
7
+def collatz(initial_number):
8
+ num = initial_number
9
+ print(f'Initial number is: {initial_number}')
10
+ while num != 1:
11
+ print(num)
12
+ if num % 2 == 0:
13
+ num = int(num / 2)
14
+ else:
15
+ num = int(3 * num + 1)
16
17
18
+ print('Finally!')
0 commit comments