-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (41 loc) · 1.13 KB
/
main.py
File metadata and controls
43 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Basics of collatz Conjecture:
# * If odd:
# 3x + 1
# * if even:
# x/2
from typing import List
import matplotlib.pyplot as plt
bullet = int(input("Enter the bullet number: "))
y_axis: List[int] = []
x_axis = []
steps = []
# print(x_axis)
while True:
if bullet % 2 == 0:
print("Even\n{}".format(bullet))
bullet //= 2
steps.append(bullet)
y_axis.append(bullet)
if bullet == 1:
print("Beginning of Conjecture")
print(steps)
break
if bullet % 2 != 0:
print("Odd\n{}".format(bullet))
bullet: int = int((3 * bullet) + 1)
steps.append(bullet)
y_axis.append(bullet)
if bullet == 1:
print("Beginning of Conjecture")
print(steps)
break
for i in range(len(y_axis)):
x_axis.append(i)
print(x_axis)
number_of_steps: int = len(steps)
print("number of steps: ", number_of_steps)
plt.plot(x_axis, y_axis, color='red', marker='o')
plt.title('Collatz Conjecture')
plt.xlabel('number', fontsize=14)
plt.ylabel('Ground', fontsize=14)
plt.show()